# 绑定社会化登录

# 绑定社会化账号

Authing.bindOAuth(options)

  • 参数:
    • {Object} options
      • type {String} 必填
      • unionid {String} 必填,OAuth返回的用户信息中的唯一ID
      • userInfo {String} 必填, JSON.strify(OAuth返回的用户信息)
      • uesr {String} 用户ID,可选,默认为当前登录用户的ID
      • client {String} 应用ID,可选,默认为当前登录应用的ID
  • 使用方法:
      (async function() {
        const authing = new Authing({
          userPoolId: 'your_userpool_id',
          secret: 'your_userpool_secret'
        });
        const bindResult = await authing.bindOAuth({
          type: 'github',
          unionid: '12345678',
          userInfo: "{"login":"demo","id":12345678,"node_id":"demodemodemo","avatar_url":"https://avatars1.githubusercontent.com/u/19266401?v=4","gravatar_id":"","url":"https://api.github.com/users/demo","html_url":"https://github.com/demo","followers_url":"https://api.github.com/users/demo/followers","following_url":"https://api.github.com/users/demo/following{/other_user}","gists_url":"https://api.github.com/users/demo/gists{/gist_id}","starred_url":"https://api.github.com/users/demo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/demo/subscriptions","organizations_url":"https://api.github.com/users/demo/orgs","repos_url":"https://api.github.com/users/demo/repos","events_url":"https://api.github.com/users/demo/events{/privacy}","received_events_url":"https://api.github.com/users/demo/received_events","type":"User","site_admin":false,"name":"demo","company":null,"blog":"","location":null,"email":"demo@gmail.com","hireable":null,"bio":"A web developer.","public_repos":10,"public_gists":0,"followers":2,"following":3,"created_at":"2016-05-09T12:43:11Z","updated_at":"2018-07-23T04:42:08Z"}"
        });
      })();
    
  • 返回数据:
      {
          "_id": "aeolkjhdhfhkkjdsfj",
          "user": "dfdfdsfdsfdsfdsfds",
          "client": "dsfjdskfjkldsjfklj",
          "type": "github",
          "userInfo": "{"login":"demo","id":12345678,"node_id":"demodemodemo","avatar_url":"https://avatars1.githubusercontent.com/u/19266401?v=4","gravatar_id":"","url":"https://api.github.com/users/demo","html_url":"https://github.com/demo","followers_url":"https://api.github.com/users/demo/followers","following_url":"https://api.github.com/users/demo/following{/other_user}","gists_url":"https://api.github.com/users/demo/gists{/gist_id}","starred_url":"https://api.github.com/users/demo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/demo/subscriptions","organizations_url":"https://api.github.com/users/demo/orgs","repos_url":"https://api.github.com/users/demo/repos","events_url":"https://api.github.com/users/demo/events{/privacy}","received_events_url":"https://api.github.com/users/demo/received_events","type":"User","site_admin":false,"name":"demo","company":null,"blog":"","location":null,"email":"demo@gmail.com","hireable":null,"bio":"A web developer.","public_repos":10,"public_gists":0,"followers":2,"following":3,"created_at":"2016-05-09T12:43:11Z","updated_at":"2018-07-23T04:42:08Z"}",
          "unionid": "12345678",
          "createdAt": "2016-05-09T12:43:11Z"
      }
    

# 获取用户已经绑定的社会化账号

Authing.readUserOAuthList(options)

  • 参数:

    • {Object} options
      • uesr {String} 用户 ID,可选,默认为当前登录用户的 ID
      • client {String} 应用 ID,可选,默认为当前登录应用的 ID
  • 使用方法:

    (async function() {
      const authing = new Authing({
        userPoolId: "your_userpool_id",
        secret: "your_userpool_secret",
      });
      const userBindedOAuthList = await authing.readUserOAuthList();
    })();
    
    • 如果 binded 为 true 则代表已经绑定
  • 返回数据:

    [
      {
        "type": "github",
        "binded": true,
        "unionid": "1122334455",
        "openid": null
      },
      {
        "type": "wechat",
        "binded": false,
        "unionid": "o4y4Cv7x2yG6VsYfpmBqnjDT928E",
        "openid": "oQwJm026TIo0YzSnD36lQJfarCR0"
      }
    ]
    

注意事项

# 解绑社会化登录账号

Authing.unbindOAuth(options)

  • 参数:
    • {Object} options
      • type {String} 必填
      • uesr {String} 用户 ID,可选,默认为当前登录用户的 ID
      • client {String} 应用 ID,可选,默认为当前登录应用的 ID
  • 使用方法:
    (async function() {
      const authing = new Authing({
        userPoolId: "your_userpool_id",
        secret: "your_userpool_secret",
      });
      const unbindedResult = await authing.unbindOAuth({
        type: "github",
      });
    })();
    
  • 返回数据:
      {
          "_id": "aeolkjhdhfhkkjdsfj",
          "user": "dfdfdsfdsfdsfdsfds",
          "client": "dsfjdskfjkldsjfklj",
          "type": "github",
          "userInfo": "{"login":"demo","id":12345678,"node_id":"demodemodemo","avatar_url":"https://avatars1.githubusercontent.com/u/19266401?v=4","gravatar_id":"","url":"https://api.github.com/users/demo","html_url":"https://github.com/demo","followers_url":"https://api.github.com/users/demo/followers","following_url":"https://api.github.com/users/demo/following{/other_user}","gists_url":"https://api.github.com/users/demo/gists{/gist_id}","starred_url":"https://api.github.com/users/demo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/demo/subscriptions","organizations_url":"https://api.github.com/users/demo/orgs","repos_url":"https://api.github.com/users/demo/repos","events_url":"https://api.github.com/users/demo/events{/privacy}","received_events_url":"https://api.github.com/users/demo/received_events","type":"User","site_admin":false,"name":"demo","company":null,"blog":"","location":null,"email":"demo@gmail.com","hireable":null,"bio":"A web developer.","public_repos":10,"public_gists":0,"followers":2,"following":3,"created_at":"2016-05-09T12:43:11Z","updated_at":"2018-07-23T04:42:08Z"}",
          "unionid": "12345678",
          "createdAt": "2016-05-09T12:43:11Z"
      }