通过oauth取得用户信息

Momo Oauth 接入遵循标准的Oauth2.0协议。

流程图

名词解释:

  1. client_id 为接入陌陌必须字段,表征此次申请的ID。
  2. client_secret 为接入陌陌必须字段,为服务器之间数据对接的密钥。
  3. scope 为陌陌对第三方开放的数据字段,多个选项使用英文逗号(,)拼接。
  4. 以上三选项,请想对接人索要。
  5. redirect_uri 为第三方需要提供的着陆页,在陌陌授权后,用户将被引导到此地址。
  6. state 第三方传递给陌陌的一个随机字符串,在授权成功后,引导到着陆页时会一起返回。

1. 跳转到授权页面

https://oauth.immomo.com/oauth/authorize

请求方式

GET

上传参数列表:

  • response_type : 固定值”code”
  • client_id
  • redirect_uri:(不传,后台取)
  • scope
  • state : 任意值,尽可能不重复使用

示例

https://oauth.immomo.com/oauth/authorize?response_type=code&client_id=mmclientdemo&redirect_uri=&scope=name,avatar&state=random_str

返回数据

查询是否已授权,如果已授权,直接返回已授权的token。

2. 用户选择是否授权

用户授权(授权页面) 用户决议:是否

3. 用户授权后服务器端跳转

返回参数

  • code
  • state 步骤1传给服务器的值

示例

http://clienturl.com?code=XXXXXXXXXXXXXX&state=random_str

4. 客户端服务器用code向Momo申请token

https://oauth.immomo.com/oauth/access_token

请求方式

POST

请求参数

  • grant_type : 固定值”authorization_code”
  • code : 上一步返回的code
  • redirect_uri
  • client_id
  • client_secret

返回参数

  • access_token
  • token_type : 固定值”bearea”
  • expires_in 默认过期时间为30天
  • refresh_token
  • scope

示例

https://oauth.immomo.com/oauth/access_token?grant_type=authorization_code&code=codedemo=redirect_uri=&client_id=client_id_demo&client_secret=client_secret_demo 以上为示例,所有参数需要用Post方式传递

{“access_token”:”access_token”,”token_type”:”bearea”,”expires_in”:2592000,”refresh_token”:””,”scope”:”name,avatar”}

5. 获取用户信息

https://oauth.immomo.com/resource/profile

请求方式

POST

请求参数

  • client_id
  • access_token : 上一步返回的字符串
  • client_secret

示例

https://oauth.immomo.com/resource/profile=?client_id=client_id_demo&access_token=access_token_demo&client_secret=client_secret_demo 以上为示例,所有参数需要用Post方式传递 {“name”:”name”,”avatar”:”http://www.immomo.com/avatar.jpg”}

Scope lists

序号名称备注
1name用户名
2avatar用户头像
3age年纪
4gender性别
5slogan个人留言
6marital情感状态
7career职业
8school学校
9hometown家乡
10book书籍
11movie电影
12music音乐
13games游戏