Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Github Login will fail upon undefined displayName #519

Closed
eric-vader opened this issue Apr 16, 2015 · 2 comments
Closed

Github Login will fail upon undefined displayName #519

eric-vader opened this issue Apr 16, 2015 · 2 comments
Assignees
Milestone

Comments

@eric-vader
Copy link

To reproduce Bug:

  1. Create a Github account without a Name.
  2. Try to add GitHub user to the application.

The application will fail without any errors to logs.

On further investigation,
the code failed in config/strategies/github.js at the line:

            // Create the user OAuth profile
            var displayName = profile.displayName.trim();

Because profile.displayName is undefined.

Suggested fix:

'use strict';

/**
 * Module dependencies.
 */
var passport = require('passport'),
    GithubStrategy = require('passport-github').Strategy,
    config = require('../config'),
    users = require('../../app/controllers/users.server.controller');

module.exports = function() {
    // Use github strategy
    passport.use(new GithubStrategy({
            clientID: config.github.clientID,
            clientSecret: config.github.clientSecret,
            callbackURL: config.github.callbackURL,
            passReqToCallback: true
        },
        function(req, accessToken, refreshToken, profile, done) {
            // Set the provider data and include tokens
            var providerData = profile._json;
            providerData.accessToken = accessToken;
            providerData.refreshToken = refreshToken;

            // Create the user OAuth profile
            // displayName may be undefined
            var displayName = profile.username || profile.displayName;
            displayName = displayName.trim();
            var iSpace = displayName.indexOf(' '); // index of the whitespace following the firstName
            var firstName =  iSpace !== -1 ? displayName.substring(0, iSpace) : displayName;
            var lastName = iSpace !== -1 ? displayName.substring(iSpace + 1) : '';

            var providerUserProfile = {
                firstName: firstName,
                lastName: lastName,
                displayName: displayName,
                email: profile.emails[0].value,
                username: profile.username,
                provider: 'github',
                providerIdentifierField: 'id',
                providerData: providerData
            };

            // Save the user OAuth profile
            users.saveOAuthUserProfile(req, providerUserProfile, done);
        }
    ));
};
@eric-vader eric-vader changed the title Github Login may fail upon undefined profile Github Login will fail upon undefined profile Apr 16, 2015
@eric-vader eric-vader changed the title Github Login will fail upon undefined profile Github Login will fail upon undefined displayName Apr 16, 2015
@codydaig
Copy link
Member

@Ericvader Does #688 solve your issue?

@ilanbiala ilanbiala added this to the 0.4.0 milestone Jul 24, 2015
@ilanbiala ilanbiala self-assigned this Jul 24, 2015
@lirantal
Copy link
Member

Closing as we already have another PR to address this which will be merged.

ilanbiala added a commit that referenced this issue Jul 24, 2015
…name

If displayName in GitHub is undefined use username
Fixes #519
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants