Keycloak Java客户端获取获取令牌

huangapple 未分类评论49阅读模式
英文:

Keycloak Java Client Get Fetching Token

问题

我需要获取rpt以便在我的应用程序中注册新用户。

Keycloak.json

{
  "realm": "master",
  "auth-server-url" : "http://localhost:8180/auth",
  "resource" : "admin-cli",
  "public-client": true
}

获取rpt:

@GetMapping("rpt")
public String token() {
    var username = environment.getProperty("authServer.admin.username");
    var password = environment.getProperty("authServer.admin.password");
    var req = new AuthorizationRequest();
    var res = this.authzClient.authorization(username, password).authorize(req);
    return res.getToken();
}

我收到以下错误:java.lang.RuntimeException: 未提供客户端密钥。

但我正在使用位于主realm下的admin-cli,其访问类型为public

我已经设置为:

  "public-client": true

如何获取admin-cli的rpt?我将在我的应用程序注册页面中使用它来创建新用户。

英文:

I need to obtain rpt in order to register new users in my app.

Keycloak.json

{
  "realm": "master",
  "auth-server-url" : "http://localhost:8180/auth",
  "resource" : "admin-cli",
  "public-client": true
}

Fetching the rpt:

@GetMapping("rpt")
public String token() {
    var username = environment.getProperty("authServer.admin.username");
    var password = environment.getProperty("authServer.admin.password");
    var req = new AuthorizationRequest();
    var res = this.authzClient.authorization(username, password).authorize(req);
    return res.getToken();
}

I get:java.lang.RuntimeException: Client secret not provided.

But I am using admin-cli that under the master realm which it's access type is public.

Already I set:

  "public-client": true

How can I obtain rpt of admin-cli? I will use it to create new users in my applications register page.

huangapple
  • 本文由 发表于 2020年5月19日 21:16:37
  • 转载请务必保留本文链接:https://java.coder-hub.com/61892016.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定