

Python3+Django2.0.4三方社交账号接入Gitee.com(码云)
source link: https://v3u.cn/a_id_154
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python3+Django2.0.4三方社交账号接入Gitee.com(码云)
码云大家都耳熟能详了,国内版的github,其三方登录的接入方式也完全照搬github经典的OAuth2逻辑。

首先注册码云的账号,随后在应用管理页面 https://gitee.com/oauth/applications,新建三方应用 :

这里创建之后可以获取到clinet_id和client_screct

图片logo可以不上传,但是应用域名和回调网址必须填写,需要注意的是必须要写完整网址也就是必须带上http或者https

随后的流程可以参照官方文档:https://gitee.com/api/v5/oauth_doc#/
第一步,通过 浏览器 或 Webview 将用户引导到码云三方认证页面上( GET请求 )
class Gitee(View):
def get(self,request):
return redirect("https://gitee.com/oauth/authorize?client_id=你的应用id&redirect_uri=http://localhost:8000/gitee_back&response_type=code")
第二步,如果用户授权登录成功,gitee则会通过回调网址将code传递给第三方应用,此时三方应用可以通过code换取access_token
class GiteeBack(View):
def get(self,request):
code = request.GET.get("code",None)
r = requests.post("https://gitee.com/oauth/token?grant_type=authorization_code&code=%s&client_id=你的应用id&redirect_uri=http://localhost:8000/gitee_back&client_secret=你的应用秘钥" % code)
print(r.text)
return HttpResponse("ok")
最后一步,码云认证服务器成功返回 access_token,三方应用通过 access_token 访问 Open API 使用用户数据。
这里我们以基础用户信息接口为例子
r = requests.get("https://gitee.com/api/v5/user?access_token=获取到的accesstoken")
print(r.text)

总体上没什么难度,需要注意一点,当需要调用openapi的接口时,需要点击授权。
访问:https://gitee.com/api/v5/swagger#/getV5User

Recommend
-
5
乾坤大挪移,如何将同步阻塞(sync)三方库包转换为异步非阻塞(async)模式?Python3.10实现。 首页 - Python
-
6
Python3+Django2集成PayPal(贝宝)跨境支付三方接口以及订单查询和退款业务首页 - Python/2020-06-14
-
3
python3.7+Django2.0.4配合vue.js2.0实现又拍云(upyun.cm)存储的异步拖拽文件上传功能首页 - Python/2020-03-21...
-
6
使用Python3.7+Django2.0.4配合vue.js2.0的组件递归来实现无限级分类(递归层级结构)首页 - Python/2020-03-03
-
7
Python3.7配合Django2.0来调用钉钉(dingding)在线api实时监测员工考勤打卡情况首页 - Python/2020-04-12
-
5
Python3.7+Django2.0.4配合Mongodb打造高性能高扩展标签云存储方案首页 - Python/2020-03-23
-
7
mpvue1.0+python3.7+Django2.0.4实现微信小程序的支付功能首页 - Python/2019-09-15
-
9
使用python3.7+Vue.js2.0+Django2.0.4异步前端通过api上传文件到七牛云云端存储首页 - Python/2020-02-24
-
10
python3.7.2+Django2.0.4 使用django-celery遇到的那些坑首页 - Python/2019-03-20 1 首先为啥要用celery
-
3
Python3.7.2+Django2.0.4 美多商城集成最新版支付宝支付接口(2019.04)首页 - Python/2019-04-10 最新版支付宝...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK