React Native集成LinkedIn API获取Access Token失败及WebView异常求助
解决 react-native-app-auth LinkedIn 登录 Error -3 问题
1. 核对重定向URI配置
- 确保LinkedIn开发者后台的授权重定向URL和代码里的
redirectUrl完全一致,包括大小写、协议(比如com.your.app://linkedin/auth)。 - iOS端检查
Info.plist是否添加对应URL Scheme:<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>com.your.app</string> <!-- 和redirectUrl的协议部分一致 --> </array> </dict> </array> - Android端检查
AndroidManifest.xml的intent-filter:<activity android:name="net.openid.appauth.RedirectUriReceiverActivity"> <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.your.app" android:host="linkedin" android:path="/auth" /> </intent-filter> </activity>
2. 检查LinkedIn应用权限和范围
- 确保请求的
scopes在LinkedIn后台已启用:至少需要r_liteprofile(获取姓名、头像)、r_emailaddress(获取邮箱),且需在应用「产品」栏添加并启用「Sign In with LinkedIn」。 - 代码中scopes配置要准确:
const config = { clientId: 'YOUR_CLIENT_ID', redirectUrl: 'com.your.app://linkedin/auth', issuer: 'https://www.linkedin.com/oauth/v2', scopes: ['r_liteprofile', 'r_emailaddress', 'openid'], };
3. 验证AppAuth配置细节
- 确认
issuer地址正确:LinkedIn的OIDC issuer是https://www.linkedin.com/oauth/v2,不要遗漏v2后缀。 - 检查LinkedIn应用后台「Auth」标签下,「OpenID Connect」是否已启用,且「回调URL」与代码中
redirectUrl完全匹配。
4. 排查WebView未自动关闭问题
- WebView未跳转回App的核心原因通常是重定向URI未被App正确捕获,回到第一步重新核对所有URI配置。
- iOS端可尝试开启
useProxy参数辅助调试:const result = await authorize(config, { useProxy: true });
5. 日志定位问题
- 开启AppAuth调试日志,查看授权流程的详细错误信息:
日志会明确显示重定向是否触发、权限请求是否被拒绝等关键信息。import { setLogger } from 'react-native-app-auth'; setLogger(console.log); // 控制台输出完整授权日志
内容的提问来源于stack exchange,提问作者Ayush
相关产品推荐
相关产品推荐

