vue.js - Vue-Authenticate for Github Login
问题描述
我使用Vue-Authenticate插件进行社交登录,这是我的 Github 登录配置
providers: {
github: {
clientId: 'my Id',
redirectUri: 'https://' + process.env.PROJECT_DOMAIN,
responseType: 'token',
authorizationEndpoint: 'https://github.com/login/oauth/authorize',
},
},
而在认证后调用方法的方法是
authenticate(provider) {
const this_ = this
this.$auth.authenticate(provider).then(function () {
const token = this_.$auth.getToken()
if (provider === 'github') {
const options = {
headers: {
Authorization: 'token ' + token,
},
}
this_.$http
.post('https://api.github.com/user', options)
.then(function (response) {
if (response.status === 200) {
const { email, name, picture } = response.data
const data = {
email,
name,
image: picture.data.url,
}
this_.createOAuth2User(data, provider)
}
})
.catch((error) => {
console.log(error)
})
}
})
},
成功验证后,我能够收到访问令牌,但是当我尝试使用该令牌访问用户详细信息并点击https://api.github.com/user
API 时,我收到 401 错误。那么在使用 github 进行身份验证时我缺少什么吗?
解决方案
推荐阅读
- docker - 在 docker 技术中,什么是“容器格式”,它是用来做什么的?
- excel - “需要对象”
- jquery - 为什么不能修改模态框内的隐藏属性?
- php - 插入前检查重复
- instagram-graph-api - Instagram-graph-api 应用评论洞察 api
- react-native - 将 expo sdk 从 30 升级到 31 后应用程序崩溃
- blockchain - 如果我们已经有了哈希值,是什么让区块链中的区块安全?
- algorithm - 使用最小二进制堆但没有更新功能的 Dijikstra 的时间复杂度是多少
- c++ - 当命名 lambda 用作模板类参数或构造函数参数时,类模板无法编译
- java - 原始错误:在 ["/usr/local/share/android-sdk/platform-tools/aapt"] Appium - Eclipse 中找不到“aapt”