o.s.s.o.provider.endpoint.TokenEndpoint : Handling error: InvalidGrantException, Bad credentials

回眸只為那壹抹淺笑 提交于 2019-12-06 16:58:45

问题


I am developing Spring Cloud authorization server, I am not getting any error when I start the server, but when I tried to access the http://localhost:9000/services/oauth/token, I get the below error.

Could you please guide what the issue is ? I wonder why its saying invalid grant though grant_type is correct ?

PluralsightSpringcloudM4SecureauthserverApplication

@SpringBootApplication
@EnableAuthorizationServer
@EnableResourceServer
@RestController
public class PluralsightSpringcloudM4SecureauthserverApplication {

    public static void main(String[] args) {
        SpringApplication.run(PluralsightSpringcloudM4SecureauthserverApplication.class, args);
    }

    @RequestMapping("/user")
    public Principal user(Principal user) {
        return user;
    }
}

ServiceConfig

@Configuration
public class ServiceConfig extends GlobalAuthenticationConfigurerAdapter {

    @Override
    public void init(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
        .withUser("agoldberg").password("pass1").roles("USER").and()
        .withUser("bgoldberg").password("pass2").roles("USER", "OPERATOR");
    }
}

application.properties

server.port=9000
security.user.name=richard
security.user.password=password
security.user.role=USER

server.contextPath=/services
security.oauth2.client.clientId=pluralsight
security.oauth2.client.clientSecret=pluralsightsecret
security.oauth2.client.authorized-grant-types=authorization_code,refresh_token,password,client_credentials
security.oauth2.client.scope=toll_read,toll_report

pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

回答1:


I had a similar issue and it was solved by defining an identifier for the password storage format.

.withUser("agoldberg").password("{noop}pass1")

More info in the following link password storage format



来源:https://stackoverflow.com/questions/49746353/o-s-s-o-provider-endpoint-tokenendpoint-handling-error-invalidgrantexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!