kev*_*ler 2 deep-linking amazon-cognito react-native expo
我需要一个用于开发的 Expo 静态深层链接,用于与 3rd 方 (Cognito) 进行 Oauth 重定向
我已经使用过,Linking.makeUrl()但这会返回一个带有动态本地 ipaddress exp://10.0.0.107:19000 的深层链接,这对于团队中的其他开发人员来说是不一致的。
文档位于:https : //docs.expo.io/versions/latest/workflow/linking/#linking-module
说各种环境链接看起来像
在世博客户端发布的应用程序: exp://exp.host/@community/with-webbrowser-redirect
独立发布的应用程序: myapp://
发展: exp://wg-qka.community.app.exp.direct:80
我已经尝试过该开发链接,但无法打开。
小智 5
我也有类似的问题,这是我的解决方案也在https://github.com/aws-amplify/amplify-js/issues/4244#issuecomment-586845322 中发布
万一有人仍然需要世博+放大+社交登录方面的帮助
应用程序.json{
"expo": {
"scheme": "exposchemeappname://" // use any name you like, just make it unique
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序.js
import { Linking } from 'expo';
import * as WebBrowser from 'expo-web-browser';
import awsconfig from './aws-exports';
const amplifyConfig = {
...awsconfig,
oauth: {
...awsconfig.oauth,
urlOpener: async (url, redirectUrl) => {
// On Expo, use WebBrowser.openAuthSessionAsync to open the Hosted UI pages.
const { type, url: newUrl } = await WebBrowser.openAuthSessionAsync(url, redirectUrl);
if (type === 'success') {
await WebBrowser.dismissBrowser();
if (Platform.OS === 'ios') {
return Linking.openURL(newUrl);
}
}
},
options: {
// Indicates if the data collection is enabled to support Cognito advanced security features. By default, this flag is set to true.
AdvancedSecurityDataCollectionFlag: true
},
}
};
const expoScheme = "exposchemeappname://"
// Technically you need to pass the correct redirectUrl to the web browser.
let redirectUrl = Linking.makeUrl();
if (redirectUrl.startsWith('exp://1')) {
// handle simulator(localhost) and device(Lan)
redirectUrl = redirectUrl + '/--/';
} else
if (redirectUrl === expoScheme) {
// dont do anything
} else {
// handle the expo client
redirectUrl = redirectUrl + '/'
}
amplifyConfig.oauth.redirectSignIn = redirectUrl;
amplifyConfig.oauth.redirectSignOut = redirectUrl;
Amplify.configure(amplifyConfig);
Run Code Online (Sandbox Code Playgroud)
确保添加以下重定向 url 以放大 amplify auth update
# development
exp://127.0.0.1:19000/--/
exp://192.168.1.101:19000/ # depends on your lan ip
# expo client
exp://exp.host/@[EXPO_ACCOUNT]/[EXPO_APPNAME]/
# expo scheme for standalone
exposchemeappname://
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2999 次 |
| 最近记录: |