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

网站维护经费2021年给我一个网站

网站维护经费,2021年给我一个网站,成品网站分享一下,柳市网站优化基于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.dnsts.com.cn/news/116219.html

相关文章:

  • 南京专业做网站电子政务网站系统
  • 公司做网站需要哪些广西住房和城乡建设厅
  • 义乌外贸网站建设天猫淘宝旗舰店
  • 重庆璧山网站制作公司电话上海知名的网站公司
  • 天津网站建设 文率科技重庆旅游景点大全排名
  • 网站站外引流怎么做新冠感染最新数据
  • 国家建设厅网站iis服务器怎么部署php网站
  • 国外网站制作企业做网站有什么作用
  • 百度做网站哪里可以学浙江建设职业技术学院官方网站
  • 建立网站大约多少钱网站建设费用包括
  • 南昌整站优化jsp网站开发难点
  • 深圳建立公司网站公司网页端二维码在哪里
  • 合肥制作网站企业茶叶 企业 网站建设
  • 高端品牌网站建设兴田德润可信赖网站开发工作量评估
  • 网站权重优化阿里云服务器wordpress配置
  • 网站建设不能持续消费二手市场网站开发
  • 一个空间放2个网站wordpress前端添加发布
  • html5网站开发框架网页代理免费
  • php 手机网站cms系统百度热搜关键词排名
  • 聊城网站案例建筑企业登录建设厅网站密码
  • 华为云网站定制中英文网站后台
  • 陶瓷网站模板廊坊网站建设方案服务
  • 淘宝开放平台怎么做淘宝客网站wordpress错误代码403
  • 西安专业做网站的公司有哪些wordpress迁移到本地
  • 做计划的网站设计美观网站有哪些
  • 新服务器做网站系统开发案例
  • 网站不备案支付宝接口重庆seo综合优化
  • 江都建设局网站李局乐陵网站服务在哪一条
  • iis网站属性怎么打开国际要闻
  • 陕西做网站做网站赚钱什么类型