Implicit Grant授权接口


1. 获取Access Token

请求地址:https://account.xiaomi.com/oauth2/authorize
请求方法:   GET
请求参数:
名称 必须 类型 备注
client_id long 申请应用时分配的 App Id
redirect_uri string 授权回调地址, 必须和申请应用是填写的一致(参数部分可不一致)
response_type string 描述获取授权的方式, Authorization Code方式授权, response_type=token
scope string 申请scope权限所需参数,可一次申请多个scope权限,用 空格分隔scope权限列表
state string 用于保持请求和回调的状态,授权请求成功后原样带回给第三方.该参数用于防止
CSRF攻击(跨站请求伪造攻击),强烈建议第三方带上该参数
skip_confirm boolean 已登录用户会看到切换帐号的页面, 如果应用不需要切换帐号, 可以加上参数skip_confirm=true,
黄页应用接入请设置为true
返回值:

如果授权成功,授权服务器会将用户的浏览器重定向到redirect_uri,并在url的Fragment里面带上access_token,token_type, expires_in, mac_algorithm, mac_key, state等参数,返回url例子如下:

http://example.com/example#access_token=TOKEN&token_type=mac&expires_in=7776000&mac_algorithm=HmacSHA1&mac_key=MACKEY&scope=SCOPE

返回参数说明:

名称 必须 类型 备注
access_token string 访问令牌
expires_in string Access Token的有效期,以秒为单位, 请参考Access Token生命周期
scope string Access Token最终的访问范围,关于权限的具体信息参考scope权限列表
mac_key string 基于http调用Open API时所需要的mac Key,其有效期与Access Token一致
mac_algorithm string 基于http调用Open API时计算参数签名时候使用的算法, 目前只支持HmacSha1
state string 如果请求时传递参数,会回传该参数

如果授权失败,授权服务器会将用户的浏览器重定向到redirect_uri,并带上error,error_description, state等参数,例子如下:

http://example.com/example?error=ERROR&error_description=ERROR_DESCRIPTION&state=STATE
名称 必须 类型 备注
error int OAuth定义的错误码
error_description string 错误描述信息
state string 如果请求时传递参数,会回传该参数