您的位置:首页 > 新闻 > 热点要闻 > 重庆制作网站怎么选_免费看电视的网站_成品短视频app下载有哪些_seo营销是什么意思

重庆制作网站怎么选_免费看电视的网站_成品短视频app下载有哪些_seo营销是什么意思

2025/2/25 4:03:22 来源:https://blog.csdn.net/Brave_heart4pzj/article/details/145522056  浏览:    关键词:重庆制作网站怎么选_免费看电视的网站_成品短视频app下载有哪些_seo营销是什么意思
重庆制作网站怎么选_免费看电视的网站_成品短视频app下载有哪些_seo营销是什么意思

文章目录

  • 一、需求概述
  • 二、开发授权服务器
    • 1、pom依赖
    • 2、yml配置
    • 3、启动服务端
  • 三、开发客户端应用
    • 1、pom依赖
    • 2、yml配置
    • 3、SecurityConfig
    • 4、接口
    • 5、测试

一、需求概述

在这里插入图片描述在这里插入图片描述在这里插入图片描述
maven需要3.6.0以上版本

二、开发授权服务器

1、pom依赖

在这里插入图片描述

        <dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-oauth2-authorization-server</artifactId></dependency>

2、yml配置

server:port: 9000logging:level:org.springframework.security: tracespring:security:# 授权服务器的账号密码user:name: adminpassword: 1111oauth2:authorizationserver:# 客户端配置client:myclient:registration:client-id: pzjclient-secret: "{noop}123456"client-authentication-methods:- "client_secret_basic"authorization-grant-types:- "authorization_code"- "refresh_token"# 客户端的回调地址redirect-uris:- "http://localhost:8080/login/oauth2/code/myclient"# 客户端的应用首页post-logout-redirect-uris:- "http://localhost:8080/"scopes:- "openid"- "profile"require-authorization-consent: true

3、启动服务端

三、开发客户端应用

1、pom依赖

        <!-- spring security 安全认证 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><!-- oauth2 客户端 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-oauth2-client</artifactId></dependency>

2、yml配置

# Spring配置
spring:security:oauth2:client:registration:myclient:provider: sasclient-id: pzjclient-secret: 123456# 重定向的url地址,这个地址为默认的redirect-uri: http://localhost:8080/login/oauth2/code/myclientauthorization-grant-type: "authorization_code"scope:- openid- profileprovider:sas:# 以下地址是默认配置在 AuthorizationServerSettings builder方法中# 授权服务器地址authorization-uri: http://oauth2-server:9000/oauth2/authorize# 获取token的地址token-uri: http://oauth2-server:9000/oauth2/token# 用于验证JWT签名的、oauth2授权服务器的公钥集合jwk-set-uri: http://oauth2-server:9000/oauth2/jwks

3、SecurityConfig

@EnableWebSecurity
@Configuration
public class SecurityConfig {@Beanprotected SecurityFilterChain filterChain(HttpSecurity http) throws Exception{http.authorizeHttpRequests(auth -> auth.anyRequest().authenticated());http.oauth2Login(Customizer.withDefaults());return http.build();}
}

4、接口

@RestController
public class HelloController {@GetMapping("/hello")public String hello(){return "<h1>hello,spring authorization server!</h1>";}
}

5、测试

浏览器访问:http://localhost:8080/hello
会跳转到
在这里插入图片描述
点击浏览器的×,进入登陆页
在这里插入图片描述
登陆后,进入授权确认页面
在这里插入图片描述
点击submit按钮,就会访问到我们的hello接口
在这里插入图片描述

工程名:authorization-project

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com