0

I need two distinct login processes in my django server.

  • Login for website users (I already have this)
  • Login for app users - Cordova InAppBrowser

The login pipeline for app users must also generate a token and return it to the Cordova app. How should I go about creating a parallel pipeline.

Ajoy
  • 1,838
  • 3
  • 30
  • 57

1 Answers1

2

So, you have two types of users in your app:

1. User
2. CordovaUser

You need two different links for two different users and somehow you should know in the pipeline that one of them is CordovaUser.

First, in your settings, do this:

FIELDS_STORED_IN_SESSION = ['user_type'] 

then the links will look like this:

1. <a href="{% url 'social:begin' 'facebook' %}">Login as User</a>
2. <a href="{% url 'social:begin' 'facebook' %}?user_type=cordova">Login as CordovaUser</a>

then customize create_user to look something like this:

def create_user(strategy, details, user=None, *args, **kwargs):
    if user:
        return {'is_new': False}

    fields = dict((name, kwargs.get(name) or details.get(name))
              for name in strategy.setting('USER_FIELDS',
                                           USER_FIELDS))
    if not fields:
        return

    user_type = strategy.session_get('type')

    if user_type != 'cordova':
        return {
            'is_new': True,
            'user': strategy.create_user(**fields)
        }
    else:
        return {
            'is_new': True,
            'user': create_cordova_user(**fields)
        }

then, create that create_cordova_user method and you are done.

Hope this helps!

Jahongir Rahmonov
  • 13,083
  • 10
  • 47
  • 91
  • Thanks for the great answer!!! One more thing. How do I return a token for the cordova user? I could append the token to the redirect url as a `GET` parameter. How should I specify the redirect? – Ajoy Sep 04 '15 at 10:11
  • @Ajoy, do you mean `access_token` of a user? If so, you can get it like so: `user.social_auth.get(provider='facebook').access_token`. If no, please can you explain what exactly it is that you are trying to do? – Jahongir Rahmonov Sep 04 '15 at 11:31
  • Not that. The server will generate a token. But how will I pass it to the cordova app? I read somewhere that it could be attached to the success callback, so that the Cordova browser can fetch the token created by the server. – Ajoy Sep 04 '15 at 11:35
  • 1
    @Ajoy you should write another question about that. I would really love to help but I don't know anything about Cordova. – Jahongir Rahmonov Sep 04 '15 at 16:36
  • I guess you are right. That should be a different question. – Ajoy Sep 04 '15 at 16:41