注册网关客户端
This commit is contained in:
@@ -8,8 +8,9 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings;
|
import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings;
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class OAuth2Config {
|
public class OAuthComponentConfig {
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -13,6 +13,7 @@ import org.springframework.security.oauth2.server.authorization.settings.ClientS
|
|||||||
import org.springframework.security.oauth2.server.authorization.settings.TokenSettings;
|
import org.springframework.security.oauth2.server.authorization.settings.TokenSettings;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@@ -43,6 +44,35 @@ public class RegisteredClientRepositoryStore {
|
|||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return new InMemoryRegisteredClientRepository(oidcClient);
|
|
||||||
|
RegisteredClient gatewayClient = RegisteredClient.withId(UUID.randomUUID().toString())
|
||||||
|
.clientId("gateway-standalone-client")
|
||||||
|
.clientSecret(bCryptPasswordEncoder.encode("gateway-secret"))
|
||||||
|
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
|
||||||
|
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
|
||||||
|
.authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
|
||||||
|
.authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS)
|
||||||
|
// 回调地址(授权码返回地址)
|
||||||
|
.redirectUris(uris -> uris.addAll(
|
||||||
|
List.of(
|
||||||
|
"http://127.0.0.1:8091/login/oauth2/code/messaging-client-oidc",
|
||||||
|
"http://127.0.0.1:9528/callback",
|
||||||
|
"http://127.0.0.1:5173/social/callback",
|
||||||
|
"http://8.147.235.150:60088/social/callback"
|
||||||
|
)
|
||||||
|
))
|
||||||
|
.postLogoutRedirectUri("http://127.0.0.1:8082/logged-out")
|
||||||
|
.scope(OidcScopes.OPENID)
|
||||||
|
.scope(OidcScopes.PROFILE)
|
||||||
|
.scope("gateway.read")
|
||||||
|
.scope("gateway.write")
|
||||||
|
.clientSettings(ClientSettings.builder().requireAuthorizationConsent(false).build())
|
||||||
|
.tokenSettings(TokenSettings.builder()
|
||||||
|
.accessTokenTimeToLive(Duration.ofHours(1))
|
||||||
|
.refreshTokenTimeToLive(Duration.ofHours(10))
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return new InMemoryRegisteredClientRepository(oidcClient, gatewayClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,12 +57,25 @@ spring:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
root: INFO
|
root: INFO
|
||||||
com.arrokoth: DEBUG
|
com.arrokoth: DEBUG
|
||||||
org.springdoc: INFO
|
org.springdoc: INFO
|
||||||
org.springframework: INFO
|
org.springframework: INFO
|
||||||
|
|
||||||
|
#mybatis:
|
||||||
|
# type-aliases-package: com.arrokoth.**.domain
|
||||||
|
# mapper-locations: classpath*:com.arrokoth/**/mapper/xml/*.xml
|
||||||
|
# configuration:
|
||||||
|
# map-underscore-to-camel-case: true
|
||||||
|
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
#mybatis-plus:
|
||||||
|
# type-aliases-package: com.arrokoth.**.domain
|
||||||
|
# mapper-locations: classpath*:com.arrokoth/**/mapper/xml/*.xml
|
||||||
|
# global-config:
|
||||||
|
# banner: true
|
||||||
|
# enable-sql-runner: true
|
||||||
|
# configuration:
|
||||||
|
# map-underscore-to-camel-case: true
|
||||||
|
# check-config-location: true
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.arrokoth.standalone.authorization;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class StandaloneServerApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user