I would like to ask you about Auth Provider:

I have a Registration Handler in a DE org linked to my Auth provider, it is working correctly and allowing the external users to register.

Now I decided to pass it to my sandbox, I created a new Auth provider, with the new reg handler. The code is the same.

The url is something like: https://test.salesforce.com/services/auth/sso/xxxxxxxxx/myAuthProvider

(in the dev org was something like https://login.salesforce.com/services/auth/sso/xxxxxxxxx/myAuthProvider)

Checking if there is a user for the email and if not create a new one with Community User profile ( High Volume Customer Portal - the org has licenses for it) .

-If there is no user that match the email a new one is created.

-If there is that is returned.

IN both cases the registration is not working in the Sandbox

However if I go to my DE org where I have the same structure created ( Auth provider + reg handler) it is working.

Code , Profiles , licenses are the same.

Here it is a example of the code ( when I say sample is because I reduce it to the simple case , no validations or checks are on it at the moment)

global class RegHandler implements Auth.RegistrationHandler{

global boolean canCreateUser(Auth.UserData data) {
    return false;

global User createUser(Id portalId, Auth.UserData data){

    String profileName = 'Community User';

    List<Profile> profiles = [SELECT Id, Name, UserType FROM Profile WHERE Name = :profileName];

    Profile profile = profiles.isEmpty() ? null : profiles[0];

        throw new RegHandlerException('Could not find the profile');

    List<User> users = [SELECT Id,Email,Username,FirstName,LastName,Alias,CommunityNickname,ProfileId,
        ContactId,LocaleSidKey,LanguageLocaleKey,TimeZoneSidKey,EmailEncodingKey FROM User WHERE  Email = :data.Email and IsActive=true]; // Standard: to exclude Guest user (etc?)Profile.UserType = 'CspLitePortal' and Name='Carolina Ruiz Medina'];//  
    User user = users.isEmpty() ? null : users[0];

        List<String> emailComponents = data.email.split('@');
        String nickname = data.attributeMap.get('display_name');
        Contact ct = new Contact(
            LastName = data.LastName,
            AccountId =  '00119000002uozp');
        upsert ct;

        user = new User(
            Email = data.email,
            Username = emailComponents[0] + '@ffcommunity.com',
            Alias = emailComponents[0].left(8),
            CommunityNickname = nickname,
            ProfileId = profile.Id,
            FirstName = data.firstName,
            LastName = data.lastName,
            LocaleSidKey = data.locale,
            LanguageLocaleKey = data.attributeMap.get('language'),
            TimeZoneSidKey = 'Europe/London',
            EmailEncodingKey  = 'ISO-8859-1',
            contactId = ct.Id


    return user;

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;

class RegHandlerException extends Exception {}

I know that the orgs that will connect with the sandbox will be also in test.salesforce.com server. ( like before the orgs connecting to my DE org where the Auth provider is working were DE orgs too)

Then in summary when I try to registre/log using auth provider URL is alwayws giving me the error:AuthorizationError?ErrorCode=NO_ACCESS&ErrorDescription=User+was+a+portal+user

Any help would be much appreciated.

(note that the Ids are hardcoded only for testing purposes :) )

  • have you tried appending "?community=[SITE URL]" to the end of the auth querystring?
    – greenstork
    Sep 2, 2014 at 16:05
  • Hi greenstork! Yes I did try, sadly with same result
    – Carolina
    Sep 2, 2014 at 16:19
  • You're obviously matching to an existing user in the org, I would try finding the user being matched as a key to this error. Go into Workbench of soqlXplorer and find all users with that email address.
    – greenstork
    Sep 2, 2014 at 16:28
  • Did any one found the solution for this issue. I am setting the same error. I am using first org community as a identity provider and second org community as service provider. Mar 2, 2015 at 10:23
  • How do you know it is a registration handler problem? Did you debug the Auth provider ?
    – compski
    Feb 25 at 11:45


You must log in to answer this question.

Browse other questions tagged .