2

In my Auth Provider RegistrationHandler, I received an instance of the Auth.UserData class, filled with users data (in this case it is an external Salesforce user). The usage is very comfortable, as long as you use the top-level attributes, or have primitive data types for every of the attributeMap. The attributeMap is a Map-String,String-, so it is easy to do something like:

DateTime cDate = DateTime.valueOf(data.attributeMap.get('created_date'));

The problem is when you have another Map as a value for the attributeMap, which will be converted by Salesforce into a single string:

--> "photos":"{picture=https://c.na24.content.force.com/profilephoto/005/F, thumbnail=https://c.na24.content.force.com/profilephoto/005/T}"

Salesforce describes this format as "a common format":

If the registration handler wants to use the rest of the data, the Auth.UserData class has an attributeMap variable. The attribute map is a map of strings (Map-String, String-) for the raw values of all the data from the third party. Because the map is -String, String-, values that the third party returns that are not strings (like an array of URLs or a map) are converted into an appropriate string representation. The map includes everything returned by the third-party authorization provider, including the items automatically converted into the common format.

My question is, has anyone ever parsed Maps from this common format?

  • What do you mean by converted by Salesforce here: "The problem is when you have another Map as a value for the attributeMap, which will be converted by Salesforce into a single string:" ? What conversion process? – Phil B May 18 '15 at 17:37
  • @PhilB : In my example with the attribute "photos" in attributeMap, I get another Map, but flattened out as a string. I can not get the thumbnail URL by simply calling data.attributeMap.get('photos').get('thumbnail'). The Auth.UserData class is populated (at least I suppose) with JSON data, which are transmitted between two orgs. Here is the describing sentence from the Salesforce Docs (yellow box): "Because the map is -String, String-, values that the third party returns that are not strings (like an array of URLs or a map) are converted into an appropriate string representation." – Nisse Knudsen May 19 '15 at 7:44
  • Are you attempting to get the thumbnail url in JavaScript or Apex? – Phil B May 19 '15 at 11:42
  • I am trying to get it in Apex. photo.thumbnail is just one example, the same format applies to other attributes. – Nisse Knudsen May 19 '15 at 12:00
  • not ideal, but why not just create a method to accept what property you want and parse the entire photos value as a string using String.split() and return the url? – Phil B May 19 '15 at 13:31
0

I had the same issue with a SSO implementation.

My approach was to rely on stiring regex and split methods. Way important was also the consistency of the data that I was receiving. So I could treat it properly.

| improve this answer | |

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.