Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
如何在 GitHub 三方授权中正确使用 access_token?_创想鸟

如何在 GitHub 三方授权中正确使用 access_token?

如何在 github 三方授权中正确使用 access_token?

github三方授权登录 access_token使用问题

在利用 github 进行三方登录时,将 access_token 放到请求头’authorization’字段可能导致获取用户令牌失败。github 授权文档说明,应使用指定格式设置 authorization 字段。

授权头格式

正确的 authorization 头格式应为:”bearer {access_token}”,其中 {access_token} 为 github 颁发的令牌。

解决方法

修改代码中的’authorization’头设置,将 access_token 使用正确的格式(bearer {access_token})进行设置。修改后的代码如下:

private async getGithubUserInfo(accessToken) {    const {ctx} = this;    // 使用accessToken去获取资源  GET https://api.github.com/user    const baseURL = 'https://api.github.com/user';    let res = await ctx.curl(baseURL, {      method: 'GET',      headers: {        'Authorization': "Bearer "+accessToken      }    })    console.log(res);  }

通过使用正确的authorization头格式,可以解决access_token无效的问题,从而成功获取用户的令牌。

以上就是如何在 GitHub 三方授权中正确使用 access_token?的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1248708.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
Pheanstalk 消息队列如何设置后台消费者执行消息处理?
上一篇 2025年12月9日 20:44:05
如何用 JavaScript 实现一个随机抽奖系统,并根据号码范围判定获奖等级?
下一篇 2025年12月9日 20:44:13

相关推荐

发表回复

登录后才能评论
关注微信