【问题标题】:How can I get userinfo from the bearer token of RedHat Openshift?如何从 RedHat Openshift 的不记名令牌中获取用户信息?
【发布时间】:2021-02-24 17:02:42
【问题描述】:

我已经在 RedHat OpenShift 上配置了 OAuth 客户端,以便我可以使用 RedHat OpenShift 集群的内置 OAuth 服务器为我的应用程序执行 SSO。我被重定向到 OCP 登录页面,通过 OCP 进行身份验证,并获得了 access_token。但现在我想从我得到的令牌中获取用户信息。但似乎 API /oauth/userinfo 没有返回用户信息。 尝试 GET /oauth/userinfo 时出现此错误

REST API /oauth/userinfo

我错过了什么吗?

【问题讨论】:

    标签: oauth-2.0 openshift redhat


    【解决方案1】:

    /oauth/userinfo 显然不存在。您可以使用 OpenShift API 本身获取用户信息/apis/user.openshift.io/v1/users/{name}

    我缺少的是当您将 ~ (波浪号)放入路径时返回当前登录的用户,所以 GET /apis/user.openshift.io/v1/users/~

    {
      kind: "User",
      apiVersion: "user.openshift.io/v1",
      metadata: {
        name: "kube:admin",
        selfLink: "/apis/user.openshift.io/v1/users/kube%3Aadmin",
        creationTimestamp: null,
      },
      identities: null,
      groups: [
        "system:authenticated",
        "system:cluster-admins",
      ],
    }
    

    当我使用 CodeReady 容器进行开发时,我的 URL 设置如下(Node.js/Next.js/next-auth):

    
    export const OpenShiftOAuthProvider = {
      id: "openshift",
      name: "OpenShift",
      type: "oauth",
      version: "2.0",
      params: { grant_type: "authorization_code" },
      scope: "user:full",
      idToken: false,
      accessTokenUrl: "https://oauth-openshift.apps-crc.testing/oauth/token",
      profileUrl: "https://api.crc.testing:6443/apis/user.openshift.io/v1/users/~",
      authorizationUrl:
        "https://oauth-openshift.apps-crc.testing/oauth/authorize?response_type=code",
      clientId: "<yourclientid>",
      clientSecret: "<yourclientsecret>"
      async profile(profile) {
        return {
          id: profile.metadata.name,
          name: profile.metadata.name
        };
      },
    };
    

    【讨论】:

    猜你喜欢
    • 2021-09-28
    • 1970-01-01
    • 2021-08-14
    • 2019-03-30
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    相关资源
    最近更新 更多