o.s.s.o.provider.endpoint.TokenEndpoint:处理错误:InvalidGrantException,凭据错误

时间:2018-04-10 06:00:34

标签: java spring-boot spring-security spring-cloud

我正在开发 Spring Cloud授权服务器,我在启动服务器时没有收到任何错误,但是当我尝试访问http://localhost:9000/services/oauth/token时,我收到以下错误。< / p>

你能指导一下这个问题吗?虽然grant_type是正确的,我想知道为什么它说无效的补助金?

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

enter image description here

的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 个答案:

答案 0 :(得分:0)

我有一个类似的问题,并且通过定义密码存储格式的标识符来解决。

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

以下链接password storage format

中的更多信息