首页 > 解决方案 > 在 ADP API 中获取 accessToken

问题描述

我正在尝试使用 NodeJS 在 ADP API 中获取 access_token。建立连接后,我可以清楚地看到我的 accessToken,但我无法访问它并使用它向其他 ADP 端点发出正确的获取请求。我试图将访问令牌设置到我的 connectionOpts 对象中。任何帮助表示赞赏

const connectionOpts = {
    clientId: 'xxxxxx',
    clientSecret: 'xxxxx',
    granttype: 'client_credentials',
    sslCertPath: './certs/xxxx_auth.pem',
    sslKeyPath: './certs/xxxx_auth.key'
}



//Create connection object for application
const connection = new adpConnection.createConnection(connectionOpts)


const connectionComplete = (error) => {
    if (error) {
        console.log('Not Connected', error)
    } else {
        console.log('Connected with Token ' + connection.accessToken) //Connected with Token 4cb1a418-f2fb-4ac2-972f-8c00b59dcff0
        connectionOpts.authCode = connection.accessToken
        console.log("ConnectionOpts", connectionOpts)
    }
}

connection.connect(connectionComplete)

标签: node.jsapiexpress

解决方案


推荐阅读