【问题标题】:Strava authorization working on local host but not when published to azureStrava 授权在本地主机上工作,但在发布到 azure 时无效
【发布时间】:2022-01-06 23:28:34
【问题描述】:

以下代码在我的网络应用中授权我的 strava 帐户:

function Authorize() {
document.location.href = "https://www.strava.com/oauth/authorize?client_id=xxxxx&redirect_uri=https://localhost:44389/home/strava&response_type=code&scope=activity:read_all"

    }

    const codeExchangeLink = `https://www.strava.com/api/v3/oauth/token`
    function codeExchange() {


        fetch(codeExchangeLink, {
            method: 'post',
            headers: {
                'Accept': 'application/json, text/plain, */*',
                'Content-Type': 'application/json'
            },

            body: JSON.stringify({
                client_id: '@ViewBag.cId',
                client_secret: '@ViewBag.cSec',
                code: '@ViewBag.code',
                //need to do this to get a new refresh token that 'reads all' and issues a new Access Token - refer to comments below
                grant_type: 'authorization_code'

            })
        })
            .then(res => res.json())
            .then(res => getActivities(res))

    }

但是,当我发布到 azure 并更改 document.location.href 代码和重定向地址(如下所示)以匹配我发布的应用程序时,它会失败并出现“错误请求”错误。

    document.location.href  = "https://www.strava.com/oauth/authorize?client_id=xxxxx&redirect_uri=https://xxxx.azurewebsites.net/home/strava&response_type=code&scope=activity:read_all"

错误如下: {"message":"Bad Request","errors":[{"resource":"Application","field":"redirect_uri","code":"invalid"}]}

非常感谢任何帮助

【问题讨论】:

    标签: asp.net azure asp.net-core strava


    【解决方案1】:

    这完全是我的错误(尴尬)。问题出在我的 Strava Api 应用程序设置中,我的回调 uri 设置为默认的“developers.strava.com”。我所要做的就是更改它以匹配我发布的 Web 应用程序 uri 'xxxx.azurewebsites.net/home/strava',它现在可以工作了。

    【讨论】:

      猜你喜欢
      • 2021-12-01
      • 2017-02-08
      • 1970-01-01
      • 2012-09-25
      • 2020-10-19
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多