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
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
}
});
}
});
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.