You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Okta认证:如何用response.params获取用户信息及解决exchangeCodeAsync报错

Expo + Okta认证:获取授权code后无法换取用户信息及exchangeCodeAsync报错

我们正在使用Expo结合Okta实现认证功能,目前已成功通过以下代码获取到授权code:

React.useEffect(() => {
    if (response?.type === 'success') {
      const { code } = response.params;
    }
  }, [response]);

但存在两个核心问题:

  • 不清楚如何使用该code获取用户的scope、邮箱、姓名等数据
  • 调用exchangeCodeAsync时触发客户端认证失败错误

补充信息

获取到的Response结构

{
    "type": "success",
    "error": null,
    "url": "http://localhost:19006/?code=fUMjE4kBX2QZXXXXXX_XXXXXXXMQ084kEPrTqDa9FTs&state=3XXXXXXXXz",
    "params": {
        "code": "fUMjE4kBX2QZXXXXXX_XXXXXXXMQ084kEPrTqDa9FTs",
        "state": "3XXXXXXXXz"
    },
    "authentication": null,
    "errorCode": null
}

exchangeCodeAsync调用详情

代码

const tokenRequestParams = {
    code: code,
    clientId: config.okta.clientId,
    redirectUri: oktaRedirectUri,
    extraParams: {
        code_verifier: authRequest.codeVerifier
    },
}

const tokenResult = await exchangeCodeAsync(tokenRequestParams, discovery);

错误信息

TokenRequest.ts:205 Uncaught (in promise) Error: Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method). The authorization server MAY return an HTTP 401 (Unauthorized) status code to indicate which HTTP authentication schemes are supported. If the client attempted to authenticate via the "Authorization" request header field, the authorization server MUST respond with an HTTP 401 (Unauthorized) status code and include the "WWW-Authenticate" response header field matching the authentication scheme used by the client.
More info: Client authentication failed. Either the client or the client credentials are invalid.
at AccessTokenRequest. (TokenRequest.ts:205:1)
at Generator.next ()
at asyncGeneratorStep (asyncToGenerator.js:3:1)
at _next (asyncToGenerator.js:22:1)


内容的提问来源于stack exchange,提问作者Mehmet Kaplan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 02:15:41