我需要一个Expo静态深层链接进行开发,以用于与第三方(Cognito)进行Oauth重定向
我用过Linking.makeUrl()
,但这会返回带有动态本地ipaddress的深层链接
exp://10.0.0.107:19000与团队中的其他开发人员不一致。
文档位于: https://docs.expo.io/versions/latest/workflow/linking/#linking-module
说各种环境链接看起来像
在Expo客户端中发布的应用:exp://exp.host/@community/with-webbrowser-redirect
独立发布的应用:myapp://
开发:exp://wg-qka.community.app.exp.direct:80
我已经尝试过“开发”链接,但是无法打开。
答案 0 :(得分:4)
我也有类似的问题,这是我的解决方案 还要在https://www.diffchecker.com/WSjAQlet
中发布万一仍然有人需要Expo + Amplify +社交登录的帮助
app.json{
"expo": {
"scheme": "exposchemeappname://" // use any name you like, just make it unique
}
}
App.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);
确保添加以下重定向网址以放大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://
答案 1 :(得分:1)
Linking
模块运行以下命令进行安装:expo install expo-linking
将其导入文件的顶部:import * as Linking from "expo-linking";
,然后使用:Linking.makeUrl();
来获取由博览会客户托管的应用程序的链接
console
即可查看网址