File tree Expand file tree Collapse file tree 4 files changed +56
-7
lines changed
java/com/example/oauth2/config Expand file tree Collapse file tree 4 files changed +56
-7
lines changed Original file line number Diff line number Diff line change @@ -17,12 +17,25 @@ POST http://localhost:8080/oauth/token
1717Content-Type: application/x-www-form-urlencoded
1818Authorization: Basic Y2xpZW50OnBhc3N3b3Jk
1919
20- code=EzNA97&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A9000%2Fcallback&scope=read_profile
20+ code=lg8HLw&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A9000%2Fcallback&scope=read_profile
21+ ###
22+
23+ #
24+ GET http://localhost:8080/oauth/authorize?client_id=client&redirect_uri=http://localhost:9000/callback&response_type=token&scope=read_profile&state=test
25+ Accept: application/json
26+ ###
27+
28+ # Password Grant Type 토큰 요청
29+ POST http://localhost:8080/oauth/token
30+ Content-Type: application/x-www-form-urlencoded
31+ Authorization: Basic Y2xpZW50OnBhc3N3b3Jk
32+
33+ username=user&password=pass&grant_type=password&scope=read_profile
2134###
2235
2336
2437GET http://localhost:8080/api/session
2538Accept: application/json
26- Authorization: Bearer 623d5bc4-7172-44ae-85c1-73a297e6ab04
39+ Authorization: Bearer 29834bce-859b-4279-b01e-76aa21465879
2740
2841###
Original file line number Diff line number Diff line change 11package com .example .oauth2 .config ;
22
3+ import lombok .AllArgsConstructor ;
34import org .springframework .context .annotation .Configuration ;
45import org .springframework .security .oauth2 .config .annotation .configurers .ClientDetailsServiceConfigurer ;
56import org .springframework .security .oauth2 .config .annotation .web .configuration .AuthorizationServerConfigurerAdapter ;
67import org .springframework .security .oauth2 .config .annotation .web .configuration .EnableAuthorizationServer ;
8+ import org .springframework .security .oauth2 .config .annotation .web .configurers .AuthorizationServerEndpointsConfigurer ;
9+ import org .springframework .security .authentication .AuthenticationManager ;
710
811@ Configuration
912@ EnableAuthorizationServer
13+ @ AllArgsConstructor
1014public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
1115
16+ private final AuthenticationManager authenticationManager ;
17+
1218 @ Override
1319 public void configure (ClientDetailsServiceConfigurer clients ) throws Exception {
1420 clients
1521 .inMemory ()
1622 .withClient ("client" )
1723 .secret ("{bcrypt}$2a$10$iP9ejueOGXO29.Yio7rqeuW9.yOC4YaV8fJp3eIWbP45eZSHFEwMG" ) // password
1824 .redirectUris ("http://localhost:9000/callback" )
19- .authorizedGrantTypes ("authorization_code" , "implicit" )
25+ .authorizedGrantTypes ("authorization_code" , "implicit" , "password" )
2026 .accessTokenValiditySeconds (120 )
27+ .refreshTokenValiditySeconds (240 )
2128 .scopes ("read_profile" );
2229 }
30+
31+
32+ @ Override
33+ public void configure (AuthorizationServerEndpointsConfigurer endpoints ) {
34+ //@formatter:off
35+ endpoints
36+ .authenticationManager (authenticationManager )
37+ ;
38+ //@formatter:on
39+ }
40+
41+
2342}
Original file line number Diff line number Diff line change 11package com .example .oauth2 .config ;
22
33import lombok .AllArgsConstructor ;
4+ import org .springframework .beans .factory .annotation .Autowired ;
45import org .springframework .context .annotation .Bean ;
6+ import org .springframework .security .authentication .AuthenticationManager ;
7+ import org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
58import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
69import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
710import org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
@@ -27,4 +30,22 @@ protected void configure(HttpSecurity http) throws Exception {
2730 public PasswordEncoder encoder () {
2831 return PasswordEncoderFactories .createDelegatingPasswordEncoder ();
2932 }
33+
34+
35+ @ Bean
36+ @ Override
37+ protected AuthenticationManager authenticationManager () throws Exception {
38+ return super .authenticationManager ();
39+ }
40+
41+ @ Autowired
42+ public void configureGlobal (AuthenticationManagerBuilder auth ) throws Exception {
43+ //@formatter:off
44+ auth
45+ .inMemoryAuthentication ()
46+ .withUser ("user" ).password ("{noop}pass" ).roles ("USER" );
47+ //@formatter:on
48+
49+ }
50+
3051}
Original file line number Diff line number Diff line change @@ -28,7 +28,3 @@ spring:
2828 initialization-mode : always
2929 platform : oauth2
3030
31- security :
32- user :
33- name : user
34- password : " {noop}pass"
You can’t perform that action at this time.
0 commit comments