Loading

微博授权第三方网站登录

大致流程如下图所述

0

前置工作

去微博开放平台上(https://open.weibo.com/)申请网站接入

0


审核通过后会给你的应用分配 App Key 和 App Secret (后续根据授权码获取access_token需要用到这个东西)

0


填写用户授权成功后的回调地址

0


1、点击社交登录按钮

0

社交按钮链接是第三方授权页

0


2、跳转到微博的授权页面

0


3、扫码登录后,跳转到回调页面,并且携带一个授权码

http://auth.gulimall.com:20000/oauth2.0/weibo/success?code =xxxxxxxx


4、在回调接口中,通过授权码,获取access_token,然后通过access_token,可以访问微博开放的相关接口

Map<String, String> map = new HashMap<>();
map.put("client_id", "2362606657");
map.put("client_secret", "78533622143269d1728d3ae6fdbd8c67");
map.put("grant_type", "authorization_code");
map.put("redirect_uri", "http://auth.gulimall.com:20000/oauth2.0/weibo/success");
map.put("code", code);
HttpResponse response = HttpUtils.doPost("https://api.weibo.com", "/oauth2/access_token", "post", new HashMap<>(), null, map);


5、在微博授权第三方应用登录时,通过access_token,去获取微博用户的相关信息,进行集成登录,相关代码自己随意实现

【注意】如果微博社交用户未注册,则进行注册并登录;如果注册了,则直接进行登录

下图可以看到,确实是以微博的用户进行登陆了

0

并且数据库中,确实生成了一条用户记录

image



相关代码可以参考: https://gitee.com/houchen1996/gulimall  下的gulimall-auth-server

posted @ 2021-12-29 18:45  青岑  阅读(340)  评论(0编辑  收藏  举报