【发布时间】:2020-05-04 17:28:59
【问题描述】:
所以我有这个代码
const auth0 = new ClientOAuth2({
clientId: 'my id',
clientSecret: 'my secret',
accessTokenUri: 'https://myorg.auth0.com/oauth/token',
scopes: ['version:read']
});
auth0.credentials.getToken().then(tok => {
console.log(tok);
}).catch(e => console.log(e));
但我收到了 403 回复
这是 auth0 建议我发送的内容
calebcushing$ curl --request POST --url https://myorg.auth0.com/oauth/token --header 'content-type: application/json' --data '{"client_id":"my id","client_secret":"my secret","audience":"http://localhost:4000","grant_type":"client_credentials"}'
curl 'https://myorg.auth0.com/oauth/token' -H 'authority: myorg.auth0.com' -H 'accept: application/json, application/x-www-form-urlencoded' -H 'origin: http://localhost:3000' -H 'authorization: Basic encoded' -H 'content-type: application/x-www-form-urlencoded' --data 'scope=version%3Aread&grant_type=client_credentials'
我没有与client-oauth2 结婚,所以如果另一个图书馆是更好的选择,那很好。我更喜欢使用 oauth 库,所以我不必做所有的协调舞蹈。如果它在向资源服务器发出请求时会自动重新获取令牌等,则可以加分。
【问题讨论】:
标签: typescript auth0