react-native - 使用 Spotify 登录后无法返回我的应用程序

标签 react-native authentication expo spotify

我正在创建一个应用程序,需要链接用户 Spotify 帐户才能获取他的音乐库。 为此,我在 React Native 上使用 expo 及其软件包“expo-auth-session

它已经有一个很好的例子来管理 connection with spotify .

不幸的是,一旦我进入 Spotify 登录页面,我就无法返回我的应用程序。我认为问题来自“redirectUri”,我不太明白它是如何工作的。我发现你应该在那里放置重定向(通常类似于 https://localhost:8000/),但我正在移动设备上工作,所以没有这样的东西。我发现您还应该在 Spotify Dashboard 上创建一个 RedirectUri 回调,但即使这样似乎也不起作用。

如果你们能获得更多有关此的信息,那就太好了!

我的开发人员:

const endPoints = {
authorizationEndpoint: "https://accounts.spotify.com/authorize",
tokenEndpoint: "https://accounts.spotify.com/api/token",};


const [request, response, promptAsync] = useAuthRequest(
    {
        clientId: "My-Client-ID",
        scopes: ["user-library-read"],
        // In order to follow the "Authorization Code Flow" to fetch token after authorizationEndpoint
        // this must be set to false
        usePKCE: false,
        // For usage in managed apps using the proxy

        redirectUri: "exp://localhost:19000",
    },
    endPoints
);

最佳答案

我将更新文档,但您应该如何配置 Spotify 的重定向 URI:

  • 设置重定向 URI:您的项目 > 编辑设置 > 重定向 URI
    • 代理:https://auth.expo.io/@username/slug
      • 如果启用了 useProxy(仅限 native ),请将 username 更改为您的 Expo 用户名,将 slug 更改为 slug 在你的 app.json 中。使用应用程序进行身份验证后,尽量不要更改应用程序的 slug,因为这可能会导致版本控制问题。
    • Expo Go:exp://localhost:19000/--/
    • 网络开发人员:https://localhost:19006
      • 重要提示:除非使用 makeRedirectUri({ path: '/' }) 在应用代码中手动更改,否则请确保网址末尾没有斜杠。
      • 运行 expo start:web --https 以使用 https 运行,否则身份验证将无法工作。
    • 自定义应用:your-scheme://
      • 方案应在 app.json expo.scheme: 'your-scheme' 中指定,然后使用 makeRedirectUri({ native: 'your-scheme://' }))
    • 网页制作:https://yourwebsite.com
      • 将其设置为您部署的网站网址。

如果未设置重定向 URI,则 Spotify 将不知道在身份验证完成后将应用程序定向到何处,这会导致您遇到“卡住”效果。

关于react-native - 使用 Spotify 登录后无法返回我的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66484115/

相关文章:

react-native - 单击按钮后,如何在react native中重定向?

android - Google Play Expo w/React - Expo 的 app.json 文件中与 Android 对应的 plist 是什么?

google-maps - Location.requestForegroundPermissionsAsync 不是函数

react-native - 如何在 React-Native (Expo) 中对图像数据进行哈希处理?

android - 如何使用 React Native VirtualizedList 遍历数据对象?

javascript - Apollo 客户端写入查询不更新 UI

c# - 以编程方式注销 ASP.NET 用户

java - 使用 pwdencrypt 时登录 从哪里开始?

php - Laravel 7.2 中的 RegistersUsers 特性

android - react native java.security.cert.CertPathValidatorException : Trust anchor for certification path not found