几个重要平台的auth2登录验证
QQ 后台方式的登录验证
http://wiki.opensns.qq.com/wiki/%E3%80%90QQ%E7%99%BB%E5%BD%95%E3%80%91%E4%BD%BF%E7%94%A8Authorization_Code%E8%8E%B7%E5%8F%96Access_Token
取得授权码 authorize_codehttps://graph.qq.com/oauth2.0/authorize (GET)
参数必须与否 描述response_type
必须
此值固定为“code”。
client_id
必须
申请QQ登录成功后,分配给应用的appid。
redirect_uri
必须
成功授权后的回调地址,域名 + 回调接口(URLEncode)。
state
必须
client端的状态值。用于第三方应用防止CSRF攻击,自定义的值。
scope
可选
请求用户授权时向用户显示的可进行授权的列表。
例如:scope=get_user_info,list_album,upload_pic,do_like
display
可选
仅PC网站接入时使用。默认展示为PC下的样式。
如果传入“mobile”,则展示为mobile端下的样式。
g_ut
可选
仅WAP网站接入时使用。
QQ登录页面版本(1:wml版本; 2:xhtml版本),默认值为1。
用户授权成功
http://.../callback.action?code=9A5F************************06AF&state=test
用户没授权:
根据授权码取得access_tokenhttp://.../callback.action?usercancel=1&state=test
https://graph.qq.com/oauth2.0/token (GET)
参数
是否必须
含义
grant_type
必须
授权类型,此值固定为“authorization_code”。
client_id
必须
网站的appid。
client_secret
必须
网站的appkey。
code
必须
上一步返回的authorization code。
注意此code会在10分钟内过期。
redirect_uri
必须
与上面一步中传入的redirect_uri保持一致。
成功取码:
access_token=FE04************************CCE2&expires_in=7776000
失败:
根据access_token获得对应用户身份的openid返回code和msg字段,以url参数对的形式返回,value部分会进行url编码
https://graph.qq.com/oauth2.0/me (GET)
参数
是否必须
含义
access_token
必须
在Step1中获取到的access token。
查询成功:
client_id
必须
string
AppKey。
redirect_uri
必须
string
授权回调地址
scope
可选
string
申请scope权限所需参数,可一次申请多个scope权限,用逗号分隔。
state
可选
string
防止跨站请求伪造(CSRF)攻击,第三方自定义串
display
可选
string
授权页面的终端类型,取值见下面的说明。
{default->web page, mobile , wap, client, apponweibo ->站内 }
forcelogin
可选
boolean
是否强制用户重新登录,true:是,false:否。默认false。
language
可选
string
授权页语言,缺省为中文简体版,en为英文版。
成功:
http://www.example.com/response&code=CODE&state
失败:
必选
类型及范围
说明
client_id
true
string
申请应用时分配的AppKey。
client_secret
true
string
申请应用时分配的AppSecret。
grant_type
true
string
请求的类型,填写authorization_code
grant_type为authorization_code时
必选
类型及范围
说明
code
true
string
调用authorize获得的code值。
redirect_uri
true
string
回调地址,需需与注册应用里的回调地址一致。
成功调用则返回:
必选
类型及范围
说明
access_token
true
string
access_token
成功返回值:
参数名称
参数说明
client_id
必选
APIKey
redirect_uri
必选
回调地址,此地址必须与在应用注册时填写的回调地址一致。
response_type
必选
此值可以为 code 或者 token。
scope
可选
申请权限的范围,缺省的scope。
如果申请多个scope,使用逗号分隔。
state
可选
第三方自定义参数。
成功:
https://www.example.com/back?code=9b73a4248
不成功:
获取access_tokenhttps://www.example.com/back?error=access_denied
https://www.douban.com/service/auth2/token (POST)
参数名称
参数说明
client_id
必选
APIKey
client_secret
必选
对应于豆瓣secret
redirect_uri
必选
回调地址
grant_type
必选
此值可以为 authorization_code 或者 refresh_token 。
code
必选
authorization_code
成功:
{"msg":"uri_not_found", "code":1001, "request":"GET \/v2\/photo\/132"}举例方式:
curl "https://api.douban.com/v2/user/~me" -H "Authorization: Bearer a14afef0f66fcffce3e0fcd2e34f6ff4"