关于第三方登录

第三方登录使用的是oauth认证,现在绝大多数是oauth2.0。

 
关于oauth的文章,推荐阅读阮一峰的这篇:
 
通常第三方公司会简化调用流程,统一规范。
提供相关的SDK,你不需要知道认证的具体步骤,根据官方文档进行配置,基本就可以完成。
官方也是推荐这种方式。
 
但有的时候,由于某些原因,需要自定义开发,那么就需要仔细的阅读官方的开发文档了。
 
以QQ登录为例:
主要流程:
0.申请得到appkey和appsecret
1.放置QQ登录图标,用户点击跳转到授权页面
https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id={0}&redirect_uri={1}&state={2}&scope=get_user_info
2.用户授权后,会跳转到上一步的redirect_uri,并且带有code参数
redirect_uri?code=CODE
3.使用code换取token
https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id={0}&client_secret={1}&code={2}&state={3}&redirect_uri={4}
4.上一步会返回token,认证完成。使用token换取openid
https://graph.qq.com/oauth2.0/me?access_token={0}
5.上一步会返回openid。接下来我们就可以使用token和openid调用具体的接口了,例如“获取用户信息接口”:
https://graph.qq.com/user/get_user_info?access_token={0}&oauth_consumer_key={1}&openid={2}
 
微博登录和微信登录,在使用code换取token,可获取到token和openid,相对QQ登录少一步。
 
原文地址:https://www.cnblogs.com/talentzemin/p/5809603.html