Недействительный токен сервера ресурсов загрузки Spring - PullRequest
0 голосов
/ 14 июля 2020

Я пытаюсь настроить OAuth2 для проекта Spring. Я использовал аутентификацию jdb c, а мой сервер авторизации и сервер ресурсов - это два отдельных API. Моя проблема теперь связана с микросервисами. Я пытаюсь использовать этот общий сервер авторизации для аутентификации микросервисов. Я могу получить access_token из конечной точки токена.

enter image description here

I can check the access_token from the check_token endpoint.

enter image description here

My resource server configuration:

@SpringBootApplication
@EnableCircuitBreaker
@EnableDiscoveryClient
@EnableResourceServer
public class ProductApiServiceApplication {

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

And application.yml:

security:
  oauth2:
    client:  
      client-id: saba-product-api-service
      client-secret: secret123 
    resource:
      id: saba-product-api-service
      token-info-uri: http://localhost:9999/uaa/oauth/check_token

And REST controller:

    @GetMapping("/user/me")
    public Principal user(Principal principal) {
        return principal;
    } 

When I call the /user/me endpoint I get invalid_token.

enter image description here

My Resource Server log:

enter image description here

And my Authorization Server log:

enter image description here

What is wrong with my code?

Update

The problem is because of this code:

введите описание изображения здесь

1 Ответ

0 голосов
/ 15 июля 2020

Наконец, я заменил

<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
    <version>2.3.4.RELEASE</version>
</dependency>

на

<dependency>
    <groupId>org.springframework.security.oauth</groupId>
    <artifactId>spring-security-oauth2</artifactId>
    <version>2.5.0.RELEASE</version>
</dependency>
        // gh-838
        if (map.containsKey("active") && !"true".equals(String.valueOf(map.get("active")))) {
            logger.debug("check_token returned active attribute: " + map.get("active"));
            throw new InvalidTokenException(accessToken);
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...