Keycloak JAX-RS和邮递员授权(Auth URL)

Pak*_*ako 5 jax-rs token oauth-2.0 postman keycloak

我有jax-rs资源并使用keycloak我想用Postman获取令牌

这是jax-rs的数据库客户端(keycloak-quickstart)

{
  "realm": "demo",
  "bearer-only": true,
  "auth-server-url": "http://localhost:8080/auth",
  "ssl-required": "external",
  "resource": "database-service"
}
Run Code Online (Sandbox Code Playgroud)

我为Postman创建了一个客户端

{
  "realm": "demo",
  "auth-server-url": "http://localhost:8080/auth",
  "ssl-required": "external",
  "resource": "client-postman",
  "credentials": {
    "secret": "b53f32d3-e15b-474b-a88d-1f1cfa68c2dc"
  }
}
Run Code Online (Sandbox Code Playgroud)

我选择了OAuth 2.0类型 在此输入图像描述

访问令牌的URL是

http://localhost:8080/auth/realms/demo/protocol/openid-connect/token
Run Code Online (Sandbox Code Playgroud)

但我不知道auth网址是 什么在此输入图像描述

dmn*_*_89 22

使用当前版本的Postman和keycloak,2.2.1.Final我设法设置了OAuth 2.0

邮差设置为keycloak

客户端密码:不是必需的,但AFAIK你可以在客户端安装它,然后你必须在这里提供它

Auth Url: https://{KEYCLOAK}/auth/realms/{REALM}/protocol/openid-connect/auth

令牌网址: https://{KEYCLOAK}/auth/realms/{REALM}/protocol/openid-connect/token

你可以从中获取这些网址 https://{KEYCLOAK}/auth/realms/{REALM}/.well-known/openid-configuration

  • 优越的答案。奇迹般有效! (2认同)

Pak*_*ako 1

我设法收到令牌,但我不知道如何调用 jax-rs 资源

我把它设置在keycloak中:

Direct Access Grants Enabled: ON
Service Accounts Enabled : ON
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

和邮递员的请求 在此输入图像描述

现在我有了令牌,我可以通过设置 jaxrs url 并在标头中调用资源 Authorization: bearer [my token]

在此输入图像描述

现在想用Postman的Authorization功能来加快步骤,直接调用资源,不知道可不可以