Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AD domain in addition to the email suffix for HRD #153

Closed
sandrinodimattia opened this issue Mar 24, 2015 · 1 comment
Closed

Support AD domain in addition to the email suffix for HRD #153

sandrinodimattia opened this issue Mar 24, 2015 · 1 comment

Comments

@sandrinodimattia
Copy link
Member

So currently the Lock will look at the email suffix (eg: jon@fabrikamcorp.com) and match this to the email domains configured for the different enterprise connections in a subscription.

Now it would make sense to extend this support to also handle domains (in the format of DOMAINNAME\USERNAME).

We now did this by injecting custom logic on events:

      var connection = '@@connection@@';
      var prompt = @@prompt@@;
      var currentUsername = null;

      var initializationOptions = {
        assetsUrl:  '@@assetsUrl@@',
        cdn:        '@@cdn@@'
      };

      var lock = new Auth0Lock('@@clientID@@', '@@auth0Domain@@', initializationOptions);

      /*
       * This will match fabrikam-adfs\jon to a connection that matches:
       *    - name == 'fabrikam-adfs'
       *    - first domain == 'fabrikam-adfs'
       */
      function findConnectionForDomain(username) {
        if (!username)
          return null;

        var domain = username.split('\\');
        if (domain.length !== 2)
          return null;

        var connections = $.map(lock.options.$client.strategies, function(n){
          $.each(n.connections, function(i, conn) {
            conn.strategy = n;
          });
          return n.connections;
        });
        if (connections.length === 1)
          return;
        var results = $.grep(connections, function(conn) { 
          return (conn.name && conn.name.toLowerCase() 
                  === domain[0].toLowerCase()) || 
            (conn.domain && conn.domain.toLowerCase() 
             === domain[0].toLowerCase());
        });
        if (results && results.length > 0)
          return results[0];  
        return null;
      }

      /*
       * If we switch over to an AD connection, make sure the current username is preserved.
       */
      lock.on('signin ready', function() {
        if (currentUsername) {
          $(lock.$container)
                .find('input[name=email]').val(currentUsername);
        }
      });
      /*
       * When the lock starts, add our custom logic to handle domain names in addition to email suffixes.
       */
      lock.once('signin ready', function(options) {

        var oldText = null;
        var currentConnection = null;

        var nextButton = $(lock.$container).find('.a0-action > button.a0-next');
        nextButton.click(function(e) {
          if (currentConnection) {
            if (currentConnection.strategy 
                && currentConnection.strategy.name === "ad") {
              connection = currentConnection.name;

              currentUsername = $(lock.$container)
                .find('input[name=email]').val();
              lock.show({
                // icon:            '{YOUR_LOGO_URL}',
                callbackURL:        '@@callbackURL@@',
                responseType:       @@callbackOnLocationHash@@ ? 'token' : 'code',
                dict:               @@dict@@,
                connections:        connection ? [connection] : null,
                rememberLastLogin:  !prompt,
                container:          'widget-container',
                authParams:         JSON.parse('{' + '@@internalOptions@@' + '}')
              });
            }
            else {
              lock.$auth0.login({
                connection: currentConnection.name
              });
            }

            e.preventDefault();
          }
        });

        // Try to match a domain every time the users leaves the username field.
        var emailField = $(lock.$container)
        .find('input[name=email]').change(function() {

          var username = $(this).val();
          var conn = findConnectionForDomain(username);
          if (conn) {
            var mailField = 
                $(lock.$container).find('.a0-email input');
            var pwdField = 
                $(lock.$container).find('.a0-password input').first();
            $(lock.$container).find('.a0-sso-notice-container')
            .removeClass('a0-hide');
            $(lock.$container).find('.a0-password')
            .addClass('a0-hide');

            oldText = nextButton.text();

            var msg = lock.options.i18n.t('signin:actionDomain');
            msg = msg.replace('{domain}', conn.name);

            nextButton.text(msg);
            nextButton.attr('title', msg);

            currentConnection = conn;

            return pwdField.attr('disabled', true);
          }
          else {
            if (oldText) {
              nextButton.text(oldText);
              nextButton.attr('title', oldText);
              oldText = null;
            }
          }
        });
      });

      lock.show({
        // icon:            '{YOUR_LOGO_URL}',
        callbackURL:        '@@callbackURL@@',
        responseType:       @@callbackOnLocationHash@@ ? 'token' : 'code',
        dict:               @@dict@@,
        connections:        connection ? [connection] : null,
        rememberLastLogin:  !prompt,
        container:          'widget-container',
        authParams:         JSON.parse('{' + '@@internalOptions@@' + '}') // Please don't remove
      });
billbonney pushed a commit to billbonney/lock that referenced this issue Jun 4, 2016
Improve A0WebKitViewController UI and customisation options
@hzalaz
Copy link
Member

hzalaz commented Aug 30, 2016

Moved to internal backlog

@hzalaz hzalaz closed this as completed Aug 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants