Expo AuthSession无法打开浏览器进行认证的问题求助
问题:Expo Go(SDK46)对接Keycloak OIDC认证时出现浏览器启动失败错误
环境信息
- Expo托管工作流,使用Expo Go作为Android调试应用
- Expo SDK版本:46
- 认证服务:Keycloak提供的OpenID Connect
代码实现
WebBrowser.maybeCompleteAuthSession(); const useProxy = false; const redirectUri = AuthSession.makeRedirectUri({ useProxy }); export default function LoginIDPScreen({ navigation }: Props) { const discovery = AuthSession.useAutoDiscovery('http://192.168.178.131:8080'); // Create and load an auth request const [request, result, promptAsync] = AuthSession.useAuthRequest({ clientId: 'titan-mobile', redirectUri, scopes: ['openid', 'profile', 'email', 'offline_access'], }, discovery); return ( <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> <Button title="Login!" disabled={!request} onPress={() => promptAsync({ useProxy }) } /> {result && <Text>{JSON.stringify(result, null, 2)}</Text>} </View> ); }
触发的错误
点击"Login"按钮后,控制台抛出以下错误:
WARN Possible Unhandled Promise Rejection (id: 0): Error: Call to function 'ExpoWebBrowser.openBrowserAsync' has been rejected. → Caused by: No matching browser activity found
已做的排查
- 手动调用
WebBrowser.openBrowserAsync('https://expo.dev')可以正常打开浏览器,因此排除设备上无可用浏览器的问题 - 当前生成的
redirectUri为exp://192.168.178.130:19000,但由于连Keycloak的认证页面都无法打开,暂时不认为这是问题根源
代理相关的额外问题
- 关闭代理(已知Expo开发环境下代理无法正常工作)时,出现上述浏览器启动失败的错误
- 启用代理时,会触发另一个错误:
ERROR Error: Cannot use the AuthSession proxy because the project full name is not defined. Prefer AuthRequest (with the useProxy option set to false) in combination with an Expo Development Client build of your application. To continue using the AuthSession proxy, specify the project full name (@owner/slug) using the projectNameForProxy option.
- 尝试在
promptAsync()中添加projectNameForProxy参数,但问题未解决 - 官方文档明确建议使用AuthSession而非AuthRequest
求各位提供解决思路?
内容的提问来源于stack exchange,提问作者Michael Kleinhenz
相关产品推荐
相关产品推荐

