我想通过javascript自动执行OAuth 2.0令牌。我有什么办法可以做到这一点,并获得在火炮上使用它的令牌。
对于OAuth令牌生成,我有以下详细信息:
- 验证网址
- 客户ID
- 范围
这是通过客户端身份验证凭据完成的。
以下是我用来生成令牌的示例代码:
var ClientOAuth2 = require('client-oauth2')
var Auth = new ClientOAuth2({
clientId: 'ClientID',accessTokenUri: 'https://Auth_URL/v2.0/token',authorizationUri: 'https://Auth_URL/v2.0/authorize',redirecturi: 'https://Auth_URL/',scope: 'api://Scope/access_as_user'
})
Auth.owner.getToken('username','password')
.then(async (user) => {
await console.log(user) //=> { accessToken: '...',tokenType: 'bearer',... }
}).catch((e) => { console.log('error show',e); })
.finally( () => console.log('end'));