Spring Security 5 OAuth2 配置

2018-08-29  本文已影响0人  Joker__k

最近有一个项目要用Spring Security做一下OAuth2登录,百度了一下发现都是基于2.x.x做的,新版的包基本上都不一样了,基于Spring Framework 5.x版本的,截止最新版本的spring-security-oauth2-x是5.0.7.RELEASE版本。

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-client</artifactId>
            <version>5.0.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-core</artifactId>
            <version>5.0.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-jose</artifactId>
            <version>5.0.7.RELEASE</version>
        </dependency>

如果是用Spring Boot进行配置的话,配置项也改掉了,需要调整。

spring.security.oauth2.client.registration.demo.client-name=demo ## registrationId
spring.security.oauth2.client.registration.demo.client-id= ## appkey
spring.security.oauth2.client.registration.demo.client-secret= ## appsecret
spring.security.oauth2.client.registration.demo.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.demo.client-authentication-method=basic
spring.security.oauth2.client.registration.demo.redirect-uri-template={baseUrl}/login/oauth2/code/{registrationId}
## 范围
spring.security.oauth2.client.registration.demo.scope= 

## 授权链接
spring.security.oauth2.client.provider.demo.authorization-uri= 
## 这个主要是一个获取密钥的URL,主要用来验证jwt的正确性(也就是签名),非jwt的可以不填
spring.security.oauth2.client.provider.demo.jwk-set-uri= 
## 通过code获取token的链接
spring.security.oauth2.client.provider.demo.token-uri= 
## 通过token获取userinfo的链接
spring.security.oauth2.client.provider.demo.user-info-uri= 
spring.security.oauth2.client.provider.demo.user-name-attribute=

虽然用application.yml进行配置会比较简洁,但是idea好像支持的不够好,对配置项是map的就提示不出来,不知道以后会不会支持

上一篇下一篇

猜你喜欢

热点阅读