小编Mat*_*ias的帖子

Spring boot 2.0.3 + 安全 + Oauth2 自动配置

Spring boot 2.0.3 + 安全 + Oauth2 自动配置

我正在使用 OAuth2 和微服务,我创建了一个微服务来生成授权令牌和另一个微服务作为客户端。令牌生成正在工作,但是当我尝试在客户端服务上使用此生成的令牌进行身份验证时,它不起作用。

生成令牌的微服务:localhost:9999

使用 url 生成的令牌:estrutura:estruturasecret@localhost:9999/oauth/token

   [
       {
          "key":"grant_type",
          "value":"password"
       },
       {
          "key":"username",
          "value":"matheus"
       },
       {
          "key":"password",
          "value":"teste"
       },
       {
          "key":"client_id",
          "value":"estrutura"
       }
    ]
Run Code Online (Sandbox Code Playgroud)

返回:

 {
        "access_token": "2e4c26b3-0fcf-493e-a255-6216b98811c5",
        "token_type": "bearer",
        "refresh_token": "5e33740a-ccb9-4ec1-94be-3a4643b8097a",
        "expires_in": 42479,
        "scope": "read write"
    }
Run Code Online (Sandbox Code Playgroud)

客户微服务:本地主机:9090

   [
       {
          "key":"grant_type",
          "value":"password"
       },
       {
          "key":"username",
          "value":"matheus"
       },
       {
          "key":"password",
          "value":"teste"
       },
       {
          "key":"client_id",
          "value":"estrutura"
       }
    ]
Run Code Online (Sandbox Code Playgroud)

应用程序.yml:

server:
  port: 9090
  servlet:
    context-path: /client
spring:
  application:
    name: client-server
  security:
    oauth2:
      client: …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security oauth-2.0 spring-boot

3
推荐指数
1
解决办法
9413
查看次数

标签 统计

java ×1

oauth-2.0 ×1

spring ×1

spring-boot ×1

spring-security ×1