Spring Security OAuth2 Client 自定义配置
Spring Security OAuth2 Spring Boot About 1,359 words添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
原始 Spring Boot 自动配置
provider
provider
下的keycloak
是自定义的名称,可任意取名。
spring:
security:
oauth2:
client:
provider:
keycloak:
issuer-uri: http://localhost:8080/realms/my-realm
registration
registration
下的keycloak
是自定义的名称,可任意取名。
keycloak
下的provider
是对应上文中的provider
下的keycloak
。
spring:
security:
oauth2:
client:
registration:
keycloak:
provider: keycloak
client-id: my-client
client-secret:
# redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
scope:
- openid
# - offline_access
# - email
# - profile
# - roles
Java 代码配置
@Bean
ClientRegistrationRepository clientRegistrationRepository() {
ClientRegistration clientRegistration = ClientRegistrations.fromIssuerLocation("http://localhost:8080/realms/my-realm")
.registrationId("keycloak")
.clientId("my-client")
.clientSecret("")
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.scope("openid")
.build();
return new InMemoryClientRegistrationRepository(clientRegistration);
}
Views: 438 · Posted: 2024-05-06
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...