Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring boot oath2无效访问令牌_Java_Spring Boot - Fatal编程技术网

Java Spring boot oath2无效访问令牌

Java Spring boot oath2无效访问令牌,java,spring-boot,Java,Spring Boot,我正在尝试一个非常简单的例子: @Configuration @EnableAuthorizationServer public class AuthorizationServer extends AuthorizationServerConfigurerAdapter { @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clien

我正在尝试一个非常简单的例子:

@Configuration
@EnableAuthorizationServer
public class AuthorizationServer extends AuthorizationServerConfigurerAdapter {

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
       clients.inMemory()
                    .withClient("my-api").secret("{noop}secret")
                    .authorizedGrantTypes("client_credentials")
                    .scopes("resource-server-read", "resource-server-write");

    }

    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
        security.allowFormAuthenticationForClients().checkTokenAccess("permitAll()");
    }
}
以及SimpleAuthorizationServer应用程序:

@RestController
@EnableResourceServer
@SpringBootApplication
public class SimpleAuthorizationServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(SimpleAuthorizationServerApplication.class, args);
    }

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

}
…然后是资源(在同一应用程序的另一个模块中):

…和

@EnableResourceServer
@SpringBootApplication
public class Application implements WebMvcConfigurer {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}
虽然我从你那里很好地拿到了代币http://localhost:7070/oauth/token :

{
    "access_token": "05a0adeb-751d-4b4b-a9f5-177e82ac9826",
    "token_type": "bearer",
    "expires_in": 42167,
    "scope": "resource-server-read resource-server-write"
}
调用资源时http://localhost:8080/hello/world 使用授权持有人代币,我可以

{
    "error": "invalid_token",
    "error_description": "Invalid access token: 05a0adeb-751d-4b4b-a9f5-177e82ac9826"
}
我的pom依赖项:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
</parent>
 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
          <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.3.3.RELEASE</version>
</dependency>
似乎有些东西配置错误,但我无法确定是什么,因此我需要帮助。

您需要设置:

security.oauth2.resource.userInfoUri=http://localhost:7070/oauth/...

这并不能回答这个问题。一旦你有足够的钱,你将能够;相反是的,在application.yml中的资源端,我尝试了:security oauth2:resource:userInfoUri:(正确缩进)相同的结果:(curl-I-H“Authorization:Bearer f782e198-fedb-49de-9131-d7c6f74c4ea8”HTTP/1.401 WWW-Authenticate:Bearer-realm=“oauth2-resource”,error=“invalid\u token”,错误描述=“无效访问令牌:f782e198-fedb-49de-9131-d7c6f74c4ea8”缓存控制:无存储X-Content-Type-Options:nosniff X-XSS-Protection:1;mode=block X-Frame-Options:DENY Content-Type:application/json;charset=UTF-8{“错误”:“无效令牌”,“错误描述”:“无效访问令牌:f782e198-fedb-49de-9131-d7c6f74c4ea8”}%您可以在授权服务器上尝试/validateUser终结点吗?授权服务器必须是该终结点的ResourceServer…以及所有其他应用程序,只有Resources server工作正常
security:
  oauth2:
    resource:
      userInfoUri: http://localhost:7070/oauth/validateUser
security.oauth2.resource.userInfoUri=http://localhost:7070/oauth/...