File tree Expand file tree Collapse file tree 3 files changed +10
-3
lines changed
oauth-authorization-server
client-server/src/main/java/com/baeldung/web
resource-server/src/main/java/com/baeldung/config
spring-authorization-server/src/main/java/com/baeldung/config Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change 1
1
package com .baeldung .web ;
2
2
3
+ import org .springframework .beans .factory .annotation .Autowired ;
3
4
import org .springframework .security .oauth2 .client .OAuth2AuthorizedClient ;
4
5
import org .springframework .security .oauth2 .client .annotation .RegisteredOAuth2AuthorizedClient ;
5
6
import org .springframework .web .bind .annotation .GetMapping ;
11
12
@ RestController
12
13
public class ArticlesController {
13
14
15
+ @ Autowired
14
16
private WebClient webClient ;
15
17
16
18
@ GetMapping (value = "/articles" )
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
13
13
http .mvcMatcher ("/articles/**" )
14
14
.authorizeRequests ()
15
15
.mvcMatchers ("/articles/**" )
16
- .access ("hasAuthority('SCOPE_article .read')" )
16
+ .access ("hasAuthority('SCOPE_articles .read')" )
17
17
.and ()
18
18
.oauth2ResourceServer ()
19
19
.jwt ();
Original file line number Diff line number Diff line change 10
10
import org .springframework .security .config .annotation .web .configuration .OAuth2AuthorizationServerConfiguration ;
11
11
import org .springframework .security .oauth2 .core .AuthorizationGrantType ;
12
12
import org .springframework .security .oauth2 .core .ClientAuthenticationMethod ;
13
+ import org .springframework .security .oauth2 .core .oidc .OidcScopes ;
13
14
import org .springframework .security .oauth2 .server .authorization .client .InMemoryRegisteredClientRepository ;
14
15
import org .springframework .security .oauth2 .server .authorization .client .RegisteredClient ;
15
16
import org .springframework .security .oauth2 .server .authorization .client .RegisteredClientRepository ;
@@ -28,12 +29,16 @@ public class AuthorizationServerConfig {
28
29
@ Bean
29
30
public RegisteredClientRepository registeredClientRepository () {
30
31
RegisteredClient registeredClient = RegisteredClient .withId (UUID .randomUUID ().toString ())
31
- .clientId ("article-client" ).clientSecret ("secret" )
32
+ .clientId ("articles-client" )
33
+ .clientSecret ("secret" )
32
34
.clientAuthenticationMethod (ClientAuthenticationMethod .BASIC )
33
35
.authorizationGrantType (AuthorizationGrantType .AUTHORIZATION_CODE )
34
36
.authorizationGrantType (AuthorizationGrantType .REFRESH_TOKEN )
35
37
.redirectUri ("http://localhost:8080/login/oauth2/code/articles-client-oidc" )
36
- .scope ("articles.read" ).build ();
38
+ .redirectUri ("http://localhost:8080/authorized" )
39
+ .scope (OidcScopes .OPENID )
40
+ .scope ("articles.read" )
41
+ .build ();
37
42
return new InMemoryRegisteredClientRepository (registeredClient );
38
43
}
39
44
You can’t perform that action at this time.
0 commit comments