Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Oauth2 Authorization Server

I setting the Spring Configuration Below:

@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

    }

}  

And Maven Setting is Below:

<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
    <version>2.0.5.RELEASE</version>
</dependency>

I Access : http://localhost:8080/oauth/token Payload grant_type=password&password=password&username=user&scope=read&client_id=my-trusted-client&client_secret=secret

But I receive error below:

{
error: "unsupported_grant_type"
error_description: "Unsupported grant type: password"
}
like image 300
JSH Avatar asked Jan 31 '15 17:01

JSH


People also ask

What is authorization server in oauth2?

At its core, an authorization server is simply an engine for minting OpenID Connect or OAuth 2.0 tokens. An authorization server is also used to apply access policies. Each authorization server has a unique issuer URI and its own signing key for tokens to keep a proper boundary between security domains.

What is spring authorization server?

An OAuth authorization server is responsible for authenticating the users and issuing access tokens containing the user data and proper access policies. In this tutorial, we'll implement a simple OAuth application using the Spring Security OAuth Authorization Server project.

How does oauth2 2.0 work in spring boot?

In Spring boot, we have one mechanism which helps us to do Authorization; this is called as oauth2. 0; by the use of this, we can easily authorize the interaction between two services. The main purpose of oauth2 is to authorize two services on behalf of the user who has access to the resource.

Is Spring Security oauth2 deprecated?

The Spring Security OAuth project has reached end of life and is no longer actively maintained by VMware, Inc. This project has been replaced by the OAuth2 support provided by Spring Security and Spring Authorization Server.


1 Answers

To use password grant you need to provide an authentication manager to the authorization server (in the empty method with the TODO in your example), so it can authenticate users. If it's a Spring Boot application there is always an AuthenticationManager available to be @Autowired.

like image 106
Dave Syer Avatar answered Feb 03 '23 09:02

Dave Syer