【发布时间】: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