1
OAuth 2.0の認証コード許可フローを実装しようとしています。しかし、トークン要求の認証ポップアップの問題に立ち往生してください。スプリングセキュリティトークン要求に認証が必要です
ここに私のコードです。
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
@Configuration パブリッククラスSecurityConfig WebSecurityConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin").password("abc").roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/login").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().permitAll()
.and().csrf().disable();
}
}
@Configuration
@EnableAuthorizationServer
public class AuthServerOAuth2Config
extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer
.tokenKeyAccess("permitAll()")
.checkTokenAccess("isAuthenticated()");
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("test")
.secret("test_secret")
.authorizedGrantTypes("authorization_code")
.scopes("write");
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints)
throws Exception {
endpoints
.authorizationCodeServices(authorizationCodeServices())
.authenticationManager(authenticationManager)
.tokenStore(tokenStore())
.approvalStoreDisabled();
}
@Bean
public TokenStore tokenStore() {
return new InMemoryTokenStore();
}
@Bean
protected AuthorizationCodeServices authorizationCodeServices() {
return new InMemoryAuthorizationCodeServices();
}
}
私は、次の手順を実行しますトークン取得するにはを拡張:
まず、それは私がユーザ名とPASSORDを入力してログインフォームに私をリダイレクトします。私は私の「テストへのアクセス権を提供することを可能にする場合は、管理者ABC
- そして、それが求められます"クライアント。
- それは「URIをリダイレクトする」ために私をリダイレクトします:
- http://localhost:8080?code=XXXは、その後、私は、コードをコピーして、トークン要求を送信するためにGoogleの高度な休息クライアントを使用:http://localhost:9000/oauth/token?client_id=test&grant_type=authorization_code&code=XXX に POSTを任意のヘッダーなし。私が理解する限り、PosterはブラウザのCookieを使用する必要があります。
- トークン要求の結果、私は、応答としてアクセストークンを取得することを期待している間に、ユーザー名とパスワードを入力するポップアップが表示されます。
、問題を解決するために私を助けてください。トークンリクエストにいくつかのヘッダーを追加する必要がありますか?または、認可サーバーの設定が間違っていますか?