查看: 8|回复: 0

集成gitee第三方登录

[复制链接]

2

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2010-5-4
发表于 2023-8-13 21:09:00 | 显示全部楼层 |阅读模式

第三方登录的原理

所谓第三方登录,实质就是 OAuth 授权。用户想要登录 A 网站,A 网站让用户提供第三方网站的数据,证明自己的身份。获取第三方网站的身份数据,就需要 OAuth 授权。

举例来说,A 网站允许 Gitee 登录,背后就是下面的流程。

  • A 网站让用户跳转到 Gitee。
  • Gitee 要求用户登录,然后询问"A 网站要求获得 xx 权限,你是否同意?"
  • 用户同意,Gitee 就会重定向回 A 网站,同时发回一个授权码。
  • A 网站使用授权码,向 Gitee 请求令牌。
  • Gitee 返回令牌.
  • A 网站使用令牌,向 Gitee 请求用户数据。

gitee中创建应用

  • 设置中点击【第三方应用】
    aa
  • 点击【创建应用】
    aa
  • 填写信息,然后点击【创建应用】
    aa

浏览器跳转gitee

写了一个html页面,只有一个链接按钮:

aa

链接的跳转地址为:

https://gitee.com/oauth/authoriclient_id=d898004fd16f0f0552578023587e98106d3f5b738e956fea31792406bf7a457d&redirect_uri=http://localhost:5000/giteeredirect.html&response_type=code

点击链接后,跳转到【OAuth 授权请求】页面:

aa

点击【同意授权】后,跳转到redirect_uri指定的地址,并且带有授权码:

http://localhost:5000/giteeredirect.html?code=7396b4fbfeb3ba669827a75421b528a90a2b6a5542f887ad8ea33187dd6bf819

aa

根据授权码获取accesstoken

获取token的地址为:

https://gitee.com/oauth/token?grant_type=authorization_code&code={code}&client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret}

这里直接用postman请求:

aa

根据token获取用户信息

接口地址为:https://gitee.com/api/v5/user

使用postman请求如下:

aa

gitee文档地址:https://gitee.com/api/v5/swagger#/getV5ReposOwnerRepoStargazers?ex=no

参考

  • https://www.ruanyifeng.com/blog/2019/04/github-oauth.html
  • https://www.cnblogs.com/lenny-z/p/15738047.html


来源:https://www.cnblogs.com/huiteresa/p/17627289.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部