Use Case:
Coming from the client website, the external users need to be log into their customer communities account without having to log again.
I know that I could use SAML for this use case, but unfortunately I couldn't use that with the customer...
So we opted for JWT authentication since that's what they use between their website and Zendesk. What I don't understand is how can I map the user that come from the external website to the right community user.
From what I understand, I need to generate the JWT token and then give it to the identity provider. But then, what else do I need to do for the SSO ? I think that I need to do something more in Salesforce, but don't even know where to begin...
I made a Registration Handler class :
global class CommunityUsersCreation implements Auth.RegistrationHandler {
global User createUser(Id portalId, Auth.UserData data){
String communityProfile = Label.Customer_Community_Plus_User;
List<Account> accounts = [SELECT Id, PersonContactId FROM Account WHERE Id IN (SELECT AccountId FROM Order)];
Profile p = [SELECT Id FROM profile WHERE name=:communityProfile LIMIT 1] ;
User u = new User();
for(Contact c : [SELECT AccountId,Id FROM Contact WHERE AccountId = :accounts]){
u.username = data.username + '.community';
u.email = data.email;
u.lastName = data.lastName;
u.firstName = data.firstName;
String alias = data.username;
//Alias must be 8 characters or less
if(alias.length() > 8) {
alias = alias.substring(0, 8);
}
u.alias = alias;
u.languagelocalekey = UserInfo.getLocale();
u.localesidkey = UserInfo.getLocale();
u.emailEncodingKey = 'UTF-8';
u.timeZoneSidKey = 'Europe/Paris';
u.profileId = p.Id;
u.contactId = c.Id;
}
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail= false;
Database.saveresult sr = Database.insert(u,dlo);
return u;
}
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);
}
Can someone help me with this please ?