0

I have created Auth provider-

Auth. Provider ID 0SO0o000000TOPA Provider Type Open ID Connect Name - Insta URL Suffix - Insta Consumer Key - Instagram consumer key Consumer Secret - Instagram consumer secret Authorize Endpoint URL- https://api.instagram.com/oauth/authorize Token Endpoint URL - https://api.instagram.com/oauth/access_token&scope=basic User Info Endpoint URL - https://api.instagram.com/v1/users/self&scope=basic Token Issuer - Default Scopes- basic Send access token in header - Checked

Send client credentials in header - Not Checked

Custom Error URL
Custom Logout URL
Registration Handler - AutocreatedRegHandler1549709582209 Execute Registration As - Amol Gaikwad Portal
Icon URL

I have created Register handler class-

global class InstagramRegHandler implements Auth.RegistrationHandler{

public static String ORG_SUFFIX = '@user.instagram.com';
private static final String DEFAULT_ACCOUNTNAME = 'Customers';
public static String EXTERNAL_USER_PROFILE = 'Customer Community User';



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

System.debug('Dumping Auth.UserData: ' + data);
System.debug('Registering Community user: ' + data.username);

   Auth.UserData d = normalizeUserData(data);

Id contactId;
contactId = createContact(d);
System.debug('Created contact: '+ contactId);            

   Profile p = [SELECT Id FROM profile WHERE name=:EXTERNAL_USER_PROFILE];
System.debug('Found profile: '+ p);

  User u = createUser(d,p);

u.contactId = contactId;
return u;

}

global void updateUser(Id userId, Id portalId, Auth.UserData data){
    System.debug('Update User called for: ' + data.email);

    User u = new User(id=userId);
    u.email = data.email;
    u.lastName = data.lastName;
    u.firstName = data.firstName;
    update(u);
}

private Auth.UserData normalizeUserData(Auth.UserData data){

    String fullname = data.fullName;
    List<String> names = fullname.split(' ', 2);
    if (names.size() >= 2){
        data.firstName = names[0];
        data.lastName = names[1]; 
    } else {
        data.LastName = fullname;
        data.FirstName = 'Unknown';
    }

   data.email = data.username + ORG_SUFFIX;

    return data;
}

private Id createContact(Auth.UserData data){
    Contact c = new Contact();

    c.email = data.email;
    c.FirstName = data.FirstName;
    c.LastName = data.LastName;

    c.Description = data.attributeMap.get('bio');

 List<Account> accounts = [select Id from Account where Name =:DEFAULT_ACCOUNTNAME];

    System.debug('Found account: ' + accounts);

    c.accountId = accounts[0].Id;            
    insert c;

    System.debug('Contact created for ' + data.email + ' id=' + c.id);

    return c.id; 
}


   private User createUser(Auth.UserData data, Profile p) {
    User u = new User();

    u.email = data.email;  
    u.username = u.email;
    u.FirstName = data.FirstName;
    u.LastName = data.LastName;

    String alias = data.username;
       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 = 'America/Los_Angeles';
            u.profileId = p.Id;

    System.debug('User staged for ' + u.username);
    return u;
}        

}

But I got the error is -

N0_Oauth_Token:Access token was not returned

  • Please use the {} button or Ctrl-K to format your code. I made this change for you but your latest edit overrode it. – David Reed Feb 12 '19 at 12:52
0

The registration handler Salesforce creates for you is just a template. You need to build it out and finish the implementation.

The most obvious culprit for the error

List has no rows for assignment to sObject

which you raised in the original version of your question is

//TODO: Get an actual account
Account a = [SELECT Id FROM account WHERE name='Acme'];

The TODO is a guide to what you need to do to fix this.

I'm not sure how you get to that line in current state, though, because your canCreateUser() is hard-coded to return false, which blocks the SSO process from continuing. That's presumably the source of the other error you see.

| improve this answer | |
  • I got the error No_Oauth_Token : Access token was not returned – Amo Gaikwad Feb 12 '19 at 12:52
  • Yes, you still need to complete the implementation of your registration handler all the way through. – David Reed Feb 12 '19 at 13:01
  • I have changed my registration handler now I get the error is Missing_value:could not find unique third-party identifier – Amo Gaikwad Feb 13 '19 at 7:38
  • Hey @AmoGaikwad, we try to keep it to one problem per post; I can't really do iterative debugging in the comments. If you have a new problem, I'd suggest you try to debug it and if you're not successful open a new, specific question about this problem. It's nice if you can preserve the original question so that my answer actually makes sense to other readers. – David Reed Feb 13 '19 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.