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

Expo Auth Session对接Keycloak配置:redirect_uri参数无效及Client ID疑问

问题1:解决"invalid_parameter: redirect_uri"错误

检查Keycloak客户端的Valid Redirect URIs配置

  • 登录Keycloak控制台,进入todo-app领域,找到react-native-client客户端
  • 在Valid Redirect URIs字段中,必须添加代码生成的完整redirect_uri。根据你的代码,生成的URI为poc-expo-router://home,直接添加该值(测试阶段可使用通配符poc-expo-router://*,生产环境建议精确配置)
  • 保存配置后重新测试

修正Keycloak发现端点URL

若你使用的是Keycloak 17及以上版本(Docker镜像默认新版本),端点路径已移除/auth前缀,需修改useAutoDiscovery的URL:

const discovery = useAutoDiscovery('http://localhost:8080/realms/todo-app')

旧版本带/auth的路径会导致发现文档加载失败,间接引发redirect_uri验证错误

确认makeRedirectUri的裸工作流适配

Expo裸工作流中,需确保scheme已在原生项目配置:

  • iOS:在Info.plist中添加CFBundleURLSchemes,包含poc-expo-router
  • Android:在AndroidManifest.xml中添加intent-filter,指定scheme为poc-expo-router
  • 可打印生成的redirect_uri确认与Keycloak配置一致:
const redirectUri = makeRedirectUri({
  scheme: 'poc-expo-router',
  path: '/home',
})
console.log('Generated redirect URI:', redirectUri)

问题2:iOS模拟器相关配置

访问本地Docker部署的Keycloak

iOS模拟器的localhost指向自身,无法访问主机Docker容器,需替换地址:

  • Mac/Windows系统:使用host.docker.internal代替localhost,修改发现URL为:
    const discovery = useAutoDiscovery('http://host.docker.internal:8080/realms/todo-app')
    
  • Linux系统:使用主机局域网IP(如192.168.1.100),并确保Docker 8080端口映射到主机

澄清"Client ID URL"疑问

你提到的"Client ID URL"应为误解:Client ID固定为react-native-client,无需额外URL配置;Keycloak的相关端点URL即为上述修正后的发现地址,直接使用即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 02:45:11