Sign UP oAuth Tokens Quickblox and oAuth

我是研究僧i 提交于 2019-12-11 09:15:09

问题


I'm working the login system with http://quickblox.com/,

I've this code to authenticate using social,(twitter this case).

var params = { 'provider': "twitter", 'keys[token]': "...", 'keys[secret]': "..."};

QB.login(params, function(err, user){
  if (user) {
    // success
  } else  {
    // error
  }
});

and this one to sign up

var params = { 'login': "emporio", 'password': "somepass"};

QB.users.create(params, function(err, user){
  if (user) {
    // success
  } else  {
    // error
  }
});

How do I sign up them if they are not registered yet?

http://quickblox.com/developers/Sample-users-javascript#Sign_In_using_Facebook.2FTwitter_access_token


回答1:


Try to sign in first and then sign ip in a case if user doesn't exist

var params = { 'login': "emporio", 'password': "somepass"};
QB.login(params, function(err, user){
  if (user) {
    // success
  } else  {

    // error, user not registered yet
    QB.users.create(params, function(err, user){
      if (user) {
        // success

        QB.login(params, function(err, user){
          if (user) {
            // success
          } else  {
            // error
          }
        });

      } else  {
        // error
      }
    });
  }
});



回答2:


So apparently the problem is how to persist user's OAuth tokens when they are not registered with your service yet but already using the site and authorised your app with Twitter.

In short - this depends on what your service does.

You can just keep them in JavaScript in the context of the current page - they will be destroyed as user close the tab.

Or you can save them in the cookies so they will be available when user comes back.

Or you can create "virtual" user in your database and save the ID of this user in cookies.

Or you can automatically register user with data queried from Twitter and log user in when authentication on twitter happens.

Anyway, when user finally register, just copy these values into appropriate field in the database.



来源:https://stackoverflow.com/questions/31713402/sign-up-oauth-tokens-quickblox-and-oauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!