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

使用react-native-app-auth的authorize()方法时出现404错误求助

解决react-native-app-auth请求OIDC发现文档404错误

错误链接的来源

react-native-app-auth遵循OpenID Connect(OIDC)的自动发现机制:当你配置issuer参数后,库会自动在该URL后拼接/.well-known/openid-configuration,请求认证服务器的发现文档——这个文档包含授权、令牌等核心端点的地址,是OIDC客户端自动配置的标准流程。你当前把issuer设为了具体的授权端点https://api.ex.fr/oauth/authorize,所以库才会生成https://api.ex.fr/oauth/authorize/.well-known/openid-configuration这个错误的请求地址,导致404。

核心修复:修正issuer配置

issuer应该是认证服务器的根域名或基础路径,而非具体的授权端点。比如你的授权端点是https://api.ex.fr/oauth/authorize,正确的issuer通常是https://api.ex.fr或https://api.ex.fr/oauth(具体取决于服务端OIDC发现文档的部署位置)。

修正后的代码示例:

import { authorize } from 'react-native-app-auth';

const config = {
  // 替换为正确的issuer基础地址
  issuer: `https://api.ex.fr/oauth`,
  clientId: `30480b7aaaaaaa0212be3`,
  redirectUrl: `com.cluster42://redirect`,
  scopes: ['public'],
};

const redirectToBrowser = async () => {
 try {
   await authorize(config);
 } catch (error) {
   console.log('error==', error)
 }
}

额外检查项

  • 先手动验证发现文档地址:在浏览器访问https://你的正确issuer/.well-known/openid-configuration,如果能返回JSON格式的发现文档,说明服务端支持自动发现;如果不支持,需要放弃issuer配置,手动指定authorizationEndpoint、tokenEndpoint等具体端点参数。
  • 确认iOS端URL Scheme配置:确保com.cluster42://redirect已在Info.plist中正确注册,避免后续授权回调失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 16:05:07