我正在尝试使用Oauth2.0提供的API实现LinkedIn登录 根据文档-https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/consumer/context
我能够获得访问代码(1步)。之后,我坚持完成新请求并出错(获取accessToken)-https://gyazo.com/abe24d7294aa4c1b9d8be9a101747ee2
尽管我确实在LinkedIn开发仪表板中配置了重定向URI-https://gyazo.com/c533a589465042342d79438eab02d2a2
我已经尝试过querystring.stringify
包中的query-string
方法
function trigerLogin() {
const accessToken = localStorage.getItem('AccessCode');
if (!accessToken) {
window.open('https://www.linkedin.com/uas/oauth2/authorization?response_type=code&state=DCEeFWf45A53sdfKef424&client_id=*************&redirect_uri=http%3A%2F%2Flocalhost%3A4000%2Fcallback&scope=r_liteprofile+r_emailaddress', '_blank', 'top=100, left=200, height=500, width=500');
}
axios.post('https://www.linkedin.com/oauth/v2/accessToken', querystring.stringify({
client_id: '*************', // for safety reasons
grant_type: 'authorization_code',
code: accessToken,
redirect_uri: 'http://localhost:4000/callback',
client_secret: '**************' // for safety reasons
}))
.then(function (response) {
console.log(response);
})
.catch(error => {console.log(error)})
}
所以我无法获得带有令牌的响应,可以进一步使用
提前谢谢!