私は、Spring Security OAuth 2.0ベースのアプリケーションをJDBCとLDAPで構成しています。 OAuth 2.0仕様では、クライアントシークレットが必要です。Spring Securityでclient_secretを使用しないでトークンを生成する方法OAuth2
私はそれがトークンを生成し、正常に動作し、次のURLを使用してトークンを生成する場合:
/oauth/token?grant_type=password&client_secret=test&client_id=test&username=test&password=test
を、私はclient_secret
なしでトークンを生成しようとすると、それが与える:
401:不正な
をerror_description:「Bad User Credentials」
が、私は次のようにclient_secret
せずにトークンを生成します:
/oauth/token?grant_type=password&username=test&password=test
securityConfig.java
:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ApplicationSecurityConfig extends WebSecurityConfigurerAdapter {
private static final int EMBEDDED_LDAP_SERVER_PORT = 33388;
@Autowired
private UserAuthenticationProvider userAuthenticationProvider;
@Autowired
private LdapAuthenticationProvider ldapAuthenticationProvider;
@Autowired
private AuthTokenStore oAuthTokenStore;
@Autowired
private AuthDelegatingAuthenticationEntryPoint delegatingAuthenticationEntryPoint;
@Override
@Qualifier("authenticationManagerBean")
@Bean
protected AuthenticationManager authenticationManager() throws Exception {
return new ProviderManager(Arrays.asList((AuthenticationProvider) ldapAuthenticationProvider,userAuthenticationProvider));
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.exceptionHandling().authenticationEntryPoint(delegatingAuthenticationEntryPoint);
}
@Bean
public ResourceServerTokenServices tokenService() {
DefaultTokenServices tokenServices = new DefaultTokenServices();
tokenServices.setTokenStore(oAuthTokenStore);
tokenServices.setReuseRefreshToken(true);
return tokenServices;
}
パスワードは、client_idだけを渡すことができます。クライアントの秘密は必要ありません。/ oauth/token?grant_type = password&username = test&password = test&client_id = CLIENT_ID' –
どうすればこのURLを使用できますか? /oauth/token?grant_type = password&username =テスト&パスワード=テスト&クライアントID = CLIENT_ID @PrasannaKumar –
セキュリティ設定のクライアントIDを言い、そのクライアントIDを渡してください... –