使用Expo AuthSession对接Azure登录后无法返回应用问题排查
Expo AuthSession 对接Azure登录点击「继续」无响应排查方案
检查Azure AD应用重定向URI匹配度
必须确保Azure门户中应用注册的重定向URI与Expo生成的redirectUri完全一致:- 调用
makeRedirectUri({})会根据环境生成不同地址,开发环境可能是exp://xxx.xxx.xxx.xxx:8081/--/,生产环境是com.garaje.OsExp:// - 把这些地址全部添加到Azure应用的「重定向URI」列表中,类型选择「公共客户端/本机(移动&桌面)」
- 调用
验证Scheme配置完整性
确认app.json/app.config.js中的scheme配置正确:{ "expo": { "scheme": "com.garaje.OsExp", // 其他Expo配置项 } }Android环境可手动检查自动生成的
AndroidManifest.xml,确保包含对应scheme的intent-filter:<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="com.garaje.OsExp" /> </intent-filter>确认redirectUri生成逻辑
在组件中打印redirectUri的值,直接复制该地址到Azure重定向URI列表:console.log('Redirect URI:', redirectUri);开发环境若使用本地IP,需确保Azure能访问到该地址,可借助Expo隧道或ngrok生成公网地址替代。
修正AuthSession核心参数
- 替换
discovery中的占位符<TenantID>为实际租户ID(组织ID或common) - 可尝试在请求配置中添加
prompt: 'login'强制触发登录流程,排查静默授权问题:const [request, , promptAsync] = useAuthRequest( { clientId, scopes: ["openid", "profile", "email", "offline_access"], redirectUri, prompt: 'login' }, discovery );
- 替换
验证导航Linking配置
确保导航容器的linking前缀包含你的scheme和Expo开发地址:const linking = { prefixes: ['com.garaje.OsExp://', 'exp://your-expo-dev-url'], // 其他Linking配置 }; <NavigationContainer linking={linking} fallback={<LoadingScreen />}> {/* 导航结构 */} </NavigationContainer>测试scheme唤起:在浏览器输入
com.garaje.OsExp://,若无法打开App,说明scheme配置未生效。
内容的提问来源于stack exchange,提问作者Julian Franco
相关产品推荐
相关产品推荐

