Spring OAuth2授权服务器

编程入门 行业动态 更新时间:2024-10-17 21:24:16
本文介绍了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授权服务器

本文发布于:2023-11-15 03:55:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1590915.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   Spring

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!