o.s.s.o.provider.endpoint.TokenEndpoint :处理错误:InvalidGrantException,错误凭据 [英] o.s.s.o.provider.endpoint.TokenEndpoint : Handling error: InvalidGrantException, Bad credentials

查看:28
本文介绍了o.s.s.o.provider.endpoint.TokenEndpoint :处理错误:InvalidGrantException,错误凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Spring Cloud 授权服务器,我在启动服务器时没有收到任何错误,但是当我尝试访问

pom.xml

<groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.4.1.RELEASE</version><relativePath/><!-- 从存储库中查找父级 --></父母><属性><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></属性><依赖项><依赖><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-oauth2</artifactId></依赖><依赖><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-security</artifactId></依赖><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></依赖><依赖><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><范围>测试</范围></依赖></依赖项><依赖管理><依赖项><依赖><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Camden.RELEASE</version><type>pom</type><范围>导入</范围></依赖></依赖项></dependencyManagement>

解决方案

我遇到了类似的问题,通过定义密码存储格式的标识符解决了这个问题.

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

以下链接中的更多信息密码存储格式

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>

解决方案

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

这篇关于o.s.s.o.provider.endpoint.TokenEndpoint :处理错误:InvalidGrantException,错误凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆