【问题标题】:o.s.s.o.provider.endpoint.TokenEndpoint : Handling error: InvalidGrantException, Bad credentialso.s.s.o.provider.endpoint.TokenEndpoint:处理错误:InvalidGrantException,错误凭据
【发布时间】:2018-09-19 15:26:48
【问题描述】:

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

您能指导一下问题是什么吗?我想知道为什么它说虽然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;
    }
}

服务配置

@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>

【问题讨论】:

  • 你知道是什么原因造成的吗?

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


【解决方案1】:

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

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

更多信息请点击以下链接password storage format

【讨论】:

    猜你喜欢
    • 2020-03-10
    • 2019-12-02
    • 2014-09-12
    • 2015-12-04
    • 2011-10-27
    • 2014-05-28
    • 1970-01-01
    • 2017-01-27
    • 2013-08-31
    相关资源
    最近更新 更多