首页 > 解决方案 > Expo React Native:Strava 身份验证进入网站

问题描述

希望有人已经对此进行了研究,并可以帮助我合并 Strava oauth。应该发生的情况是用户单击了使用 strava 连接按钮,并且在授权应用程序后应该重定向到 myApp。但是,strava 说 redirectURL 对于前 2 个选项无效(因为它是一个包含 expo URL 的字符串,即使它是一个独立的托管工作流应用程序)。myApp 的第三个选项是有效的,但不会将用户重定向回应用程序或任何东西。第四个选项有效,但是用户被重定向到网站,这当然不是目标。

const openStravaAuth = async () => {
  // These do not work
  // const redirect = await Linking.getInitialURL() + '/stravaAuth'
  // const redirect = Linking.makeUrl('/stravaAuth')
  // const redirect = 'myApp://myApp.com'

  // This does work, but redirects user to browser and that will create a whole new user if they are not logged in there
  const redirect = 'https://myApp.com/stravaAuth' // This one works
  
  const url = `https://www.strava.com/oauth/authorize?client_id=${STRAVA_CLIENT_ID}&response_type=code&redirect_uri=${redirect}&approval_prompt=force`

  const result = await WebBrowser.openAuthSessionAsync(url, redirect)
}

标签: react-nativeexpo

解决方案


推荐阅读