【问题标题】:expo-auth-session - Two app options on return to appexpo-auth-session - 返回应用程序时的两个应用程序选项
【发布时间】:2021-11-18 11:45:29
【问题描述】:

SDK 版本:43.0.0

平台(Android/iOS/web/all):Android

您好,我在托管工作流程中使用 expo-auth-session 通过其官方 API 收集 Instagram 用户数据,它在开发环境中运行良好(通过“expo run:android”命令),但是一旦build APK 是在用户进行授权过程并且重定向开始时创建的,有一个弹出窗口询问“打开方式”和我的应用程序的两个选项,第一个完美运行第二个返回应用程序但什么也不做,我没有不要在 IOS 上测试。

这是代表它的图像: Click here to see

在开发时,我尝试执行 google 登录过程,但遇到了同样的错误,通过实现 google 原生登录部分解决了。我在 app.json 中验证了我的方案,但没有发现错误,如下:

app.json:

{
    "expo": {
        "name": "Secreet",
        "slug": "secreet",
        "version": "1.0.0",
        "orientation": "portrait",
        "icon": "./assets/icon.png",
        "scheme": "com.davidtmiranda.secreet",
        "splash": {
            "image": "./assets/splash.png",
            "resizeMode": "contain",
            "backgroundColor": "#ffffff"
        },
        "updates": {
            "fallbackToCacheTimeout": 0
        },
        "assetBundlePatterns": ["**/*"],
        "ios": {
            "supportsTablet": true,
            "usesAppleSignIn": true,
            "bundleIdentifier": "com.davidtmiranda.secreet",
            "googleServicesFile": "./GoogleService-Info.plist",
            "config": {
                "googleSignIn": {
                    "reservedClientId": "com.googleusercontent.apps.--------------------"
                }
            }
        },
        "android": {
            "versionCode": 1,
            "adaptiveIcon": {
                "foregroundImage": "./assets/adaptive-icon.png",
                "backgroundColor": "#FFFFFF"
            },
            "package": "com.davidtmiranda.secreet",
            "googleServicesFile": "./google-services.json"
        },
        "web": {
            "favicon": "./assets/favicon.png"
        }
    }
}

另外,我的 authSession 代码如下所示:

    webBrowser.maybeCompleteAuthSession();
    const useProxy = Platform.select({ web: false, default: true });

    const client_id = ---;
    const redirect_uri = "https://auth.expo.io/@davidtmiranda/secreet";
    const scope = "user_profile";

    const site =
        "https://api.instagram.com/oauth/authorize?client_id=" +
        client_id +
        "&redirect_uri=" +
        redirect_uri +
        "&scope=" +
        scope +
        "&response_type=code&state=1";

    const discovery = { authorizationEndpoint: site };

    const [request, response, promptAsync] = useAuthRequest(
        {
            redirectUri: makeRedirectUri({
                useProxy,
                native: redirect_uri,
            }),
            scopes: [scope],
            clientId: String(client_id),
        },
        discovery
    );

    useEffect(() => {
        if (response?.type === "success") {
       ...
        } 
    }, [response]);

    function GetInstagramID() {
        return promptAsync({
            useProxy,
        });
    }

关于如何解决这个问题的任何建议?我认为它与架构有关,但无法确定问题所在。

【问题讨论】:

    标签: android react-native oauth-2.0 expo url-scheme


    【解决方案1】:

    也许你可以尝试删除app.json中的scheme

    "scheme": "com.davidtmiranda.secreet",
    

    它会在android/app/build.gradle 中更改appAuthRedirectScheme

    manifestPlaceholders = [appAuthRedirectScheme: 'com.davidtmiranda.secreet']
    

    它解决了我的问题。

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    • 谢谢,这对我有用!我已将 scheme 明确设置为等于我的 android.package 但事实证明我应该让 expo 处理它。
    • 这对我不起作用,当我这样做时,我得到了重定向但没有任何数据,如果我将包名称作为方案,我得到与 OP 相同的错误。
    猜你喜欢
    • 2022-10-13
    • 2021-02-10
    • 2021-02-02
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 1970-01-01
    相关资源
    最近更新 更多