昨天我尝试获取 docusigns api 以验证用户并获取访问令牌。但是,当我尝试按此处所述获取访问令牌时,出现 invalid_rant 错误。 https://developers.docusign.com/platform/auth/authcode/authcode-get-token/
我设法通过客户端获取授权代码,这是我的服务器端代码,我从查询参数接收代码以请求访问令牌。在获取中,我还尝试使用 JSON.stringify 作为正文,但无济于事。
import { Controller, Get, Query } from '@nestjs/common';
import { json } from 'stream/consumers';
@Controller('docusign')
export class DocusignController {
@Get("access_token")
async getAccessToken(@Query("code") code:string) {
const auth_header = "Basic "+btoa(process.env.Docusing_Integration_Key+":"+process.env.Docusign_Auth_Secret);
//Cambiar a este url para produccion https://account.docusign.com/oauth/token
let res= await fetch('https://account-d.docusign.com/oauth/token',{
method: 'POST',
headers: {
"Authorization":auth_header
},
body:`grant_type=authorization_code&code=${code}`
})
console.log(await res.json())
}
}
我昨天很抱歉无法解决它,但今天我意识到我只是缺少将内容类型添加到标题中。
@Get("access_token")
async getAccessToken(@Query("code") code:string) {
const auth_header = "Basic "+btoa(process.env.Docusing_Integration_Key+":"+process.env.Docusign_Auth_Secret);
console.log(auth_header)
console.log(code)
//Cambiar a este url para produccion https://account.docusign.com/oauth/token
let res= await fetch('https://account-d.docusign.com/oauth/token',{
method: 'POST',
headers: {
"Authorization":auth_header,
'Content-Type': 'application/x-www-form-urlencoded'//<-- add this line
},
body:`grant_type=authorization_code&code=${code}`
})
console.log(await res.json())
}