当前位置: 首页 > news >正文

网站维护经费影响网站打开速度

网站维护经费,影响网站打开速度,手游传奇新开服网站,中国徐州网官网基于SpringBoot和OAuth2#xff0c;实现通过Github授权登录应用 文章目录 基于SpringBoot和OAuth2#xff0c;实现通过Github授权登录应用0. 引言1. 创建Github应用2. 创建SpringBoot测试项目2.1 初始化项目2.2 设置配置文件信息2.3 创建Controller层2.4 创建Html页面 3. 启动…基于SpringBoot和OAuth2实现通过Github授权登录应用 文章目录 基于SpringBoot和OAuth2实现通过Github授权登录应用0. 引言1. 创建Github应用2. 创建SpringBoot测试项目2.1 初始化项目2.2 设置配置文件信息2.3 创建Controller层2.4 创建Html页面 3. 启动应用4. 其他 0. 引言 在注册登录网站或者应用时通常会有社交方式登录例如在登录CSDN时会提供多种登陆方式如下图。 本文介绍通过SpringBoot和OAuth2开发自己的应用并实现通过Github授权登录。 1. 创建Github应用 首先登录Github进入到Settings-Developer Settings点击OAuth Apps新建New OAuth App 填写相关信息 点击注册应用 注册完成后打开可以获得Client ID 和Client secrets 注意 Client secrets要注意复制下来保存不然在进入这个页面也获取不到原来完整的Client secrets了只能重新生成 2. 创建SpringBoot测试项目 2.1 初始化项目 初始化项目同时应包含以下依赖 Spring Web Thymeleaf Spring Security OAuth2 Client创建完成后创建Controller文件和index文件。最终项目结构目录如下 2.2 设置配置文件信息 application.yml spring:security:oauth2:client:registration:github:client-id: xxxclient-secret: xxx将上面生成的client-id和client-secret写入配置文件 2.3 创建Controller层 IndexController.java import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient; import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping;/*** author SaoE* date 2024/12/29 21:29*/ Controller public class IndexController {GetMapping(/)public String index(Model model,RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient authorizedClient,AuthenticationPrincipal OAuth2User oauth2User) {model.addAttribute(userName, oauth2User.getName());model.addAttribute(clientName, authorizedClient.getClientRegistration().getClientName());model.addAttribute(userAttributes, oauth2User.getAttributes());return index;} } 2.4 创建Html页面 resources/templates/index.html !DOCTYPE html html xmlnshttp://www.w3.org/1999/xhtml xmlns:thhttps://www.thymeleaf.org xmlns:sechttps://www.thymeleaf.org/thymeleaf-extras-springsecurity5 headtitleSpring Security - OAuth 2.0 Login/titlemeta charsetutf-8 / /head body div stylefloat: right th:fragmentlogout sec:authorizeisAuthenticated()div stylefloat:leftspan stylefont-weight:boldUser: /spanspan sec:authenticationname/span/divdiv stylefloat:nonenbsp;/divdiv stylefloat:rightform action# th:action{/logout} methodpostinput typesubmit valueLogout //form/div /div h1OAuth 2.0 Login with Spring Security/h1 divYou are successfully logged in span stylefont-weight:bold th:text${userName}/spanvia the OAuth 2.0 Client span stylefont-weight:bold th:text${clientName}/span /div divnbsp;/div divspan stylefont-weight:boldUser Attributes:/spanulli th:eachuserAttribute : ${userAttributes}span stylefont-weight:bold th:text${userAttribute.key}/span: span th:text${userAttribute.value}/span/li/ul /div /body /html3. 启动应用 在浏览器输入并访问http://localhost:8080/此时浏览器将被重定向到默认的自动生成的登录页面该页面显示了一个用于GitHub登录的链接。 点击授权 此时OAuth客户端访问GitHub的获取用户信息的接口获取基本个人资料信息并建立一个已认证的会话。 4. 其他 在SpringBoot源码的CommonOAuth2Provider类中默认配置了GOOGLE、FACEBOOK、GITHUB和OKTA的授权登录配置 以Github为例默认配置如下 GITHUB {public Builder getBuilder(String registrationId) {Builder builder this.getBuilder(registrationId, ClientAuthenticationMethod.CLIENT_SECRET_BASIC, {baseUrl}/{action}/oauth2/code/{registrationId});builder.scope(new String[]{read:user});builder.authorizationUri(https://github.com/login/oauth/authorize);builder.tokenUri(https://github.com/login/oauth/access_token);builder.userInfoUri(https://api.github.com/user);builder.userNameAttributeName(id);builder.clientName(GitHub);return builder;}},
http://www.hkea.cn/news/14545419/

相关文章:

  • 网站建设大概要多少钱建设银行 企业
  • 做网站怎么开发程序如何在iis下建设网站
  • 做女装代理需要自建网站么群晖wordpress配置
  • 以前的网站忘了怎么办啊团购网站制作
  • 黑客攻击的网站wordpress大学 视频教程
  • 视频制作素材网站做诚信通谁给做网站
  • 山西网站建设自助业务网站系统
  • 外贸建站网站建设吉工之家找工作建筑工作
  • win2003网站建设搜索引擎关键词怎么优化
  • 精品课程网站建设 公司广告设计自学网教程
  • 茂名专业网站建设99作文网
  • 网页设计与网站建设的报告小型企业门户网站制作
  • 动态效果的网站建设网站网页基本情况 网页栏目设置
  • wordpress标签云插件下载哈尔滨做网站seo
  • 泰安网站建设公司做网站诱导网站
  • 第三方网站宣传怎么做建立一个国外的网站
  • 北京网站建设有限公司做网站自己租服务器还是网络公司
  • 天津市北辰区建设与管理局网站网站建设里面包含什么语言
  • 云虚拟主机怎么做网站html5购物网站源码
  • 网站做3儿童车开场动画上海建站网络科技
  • 做网站需要域名还需要什么wordpress 转发
  • 襄阳做网站的做网站代码保密协议
  • 别的网站可以做弹幕模块化网站建设
  • 重庆网站建设电话百度如何优化
  • 电子商务网站开发相关技术网站建设选谋者
  • 网站开发的标准银川品牌网站建设公司
  • 专注专业网站建设新手学网页设计的网站
  • 公司资质查询官方网站为什么自己花钱做的网站竟然不是自己的 (
  • 黄页网站推广app软件郑州房地产网站建设
  • 那家网站建设公司好口碑好的赣州网站建设