本文介绍了Spring OAuth2授权服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面设置了Spring配置:
@EnableAuthorizationServer @EnableWebSecurity @Configuration public class Oauth2Provider extends WebSecurityConfigurerAdapter implements AuthorizationServerConfigurer { /* * @Autowired private TokenStore tokenStore; */ @Configuration protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter { @Override public void init(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().withUser("user").password("password") .roles("USER").and().withUser("admin").password("password") .roles("USER", "ADMIN"); } } @Override public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { // TODO Auto-generated method stub security.allowFormAuthenticationForClients(); } @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { // TODO Auto-generated method stub clients.inMemory() .withClient("my-trusted-client") .authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit") .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT", "ROLE_ANONYMOUS") .scopes("read", "write", "trust") .secret("secret") .accessTokenValiditySeconds(60); } @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { // TODO Auto-generated method stub } }和Maven设置如下:
<dependency> <groupId>org.springframework.security.oauth</groupId> <artifactId>spring-security-oauth2</artifactId> <version>2.0.5.RELEASE</version> </dependency> 我访问: localhost:8080/oauth/token 有效载荷 Grant_type=password&;password=password&;username=user&;scope=read&;client_id=my-trusted-client&;client_secret=secret但我收到以下错误:
{ error: "unsupported_grant_type" error_description: "Unsupported grant type: password" } 推荐答案要使用密码授予,您需要向授权服务器提供身份验证管理器(在您的示例中使用带有TODO的空方法),以便它可以对用户进行身份验证。如果是Spring Boot应用程序,则始终有AuthenticationManager可用@Autowired。
更多推荐
Spring OAuth2授权服务器
发布评论