Last active
October 11, 2016 15:18
-
-
Save danlester/e9e6d3db464f0609d137e3370715de2b to your computer and use it in GitHub Desktop.
Google Apps Login for Salesforce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class GACentric_Google_RegHandler implements Auth.RegistrationHandler{ | |
global User createUser(Id portalId, Auth.UserData data){ | |
List<User> users = [SELECT Id, username, email FROM User WHERE email = :data.email]; | |
if (users.size() == 0) { | |
return null; | |
} | |
if (users.size() == 1) { | |
return users[0]; | |
} | |
for (User u : users) { | |
// Find the user with username also matching incoming email address as a preference | |
if (u.username == data.email) { | |
return u; | |
} | |
} | |
// Just return the first since no username match found | |
return users[0]; | |
} | |
global void updateUser(Id userId, Id portalId, Auth.UserData data){ | |
User u = new User(id=userId); | |
u.email = data.email; | |
u.lastName = data.lastName; | |
u.firstName = data.firstName; | |
update(u); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment