function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JPSeaburyJPSeabury 

How can I programmatically get the ID of an Identity Auth. Provider registered in Salesforce?

All of the documented AuthToken methods seem to pass hardcoded values for the Identity Auth. Provider Id (see documentation here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Auth_AuthToken.htm).

Samples:

String accessToken = Auth.AuthToken.getAccessToken('0SOD000000000De', 'Open ID connect');
Map<String, String> responseMap = Auth.AuthToken.refreshAccessToken('0SOD000000000De', 'Open ID connect', accessToken);the 

I know that using hardcoded Id values in Apex is a no-no, but to get my code up and running, I quickly used hardcoded ID values for Identity Auth Providers in my code. Everything works great in the sandbox, but now that I'm getting ready to deploy to Prod, I'm aware that I'll run into issues. Auth Providers deployed into Production will have a different Id value than those created in the Sandbox. I need to harden the apex code so that it no longer uses these hardcoded Auth Provider ID values.

How can I get the Id value of an Identity Auth Provider regsitered in my org? I don't think I can pull that back with a SOQL statement (similar to how I'd pull back Id values of Profiles, Queues or other objects, can I?

SELECT id FROM ??? 

Thanks for the help, bonus karma points for sample code!

gdm1986gdm1986
I suggest you use custom labels for your use case - it will be the same but it won't require a code update if the value changes. Let me know if that helps. I'm  having to access this value at runtime because I have several auth providers and need to know which one is passing through. I'm in the registration handler and I need to access the Auth Provider's id via Apex because I'm running some security checks against the ThirdPartyAccountLink table. At the end of the execution, a user is provisioned and the ThirdPArtyAccountLink table adds a record for the user referencing the Auth Provider ID in the key (so it is in context). Any help is greatly appreciated! 
gdm1986gdm1986
So, the issues is that I have 14 Auth providers all hitting the same registration handler. Which one is the one that went through the OpenId Connect Claim process and hit the registration handler before going through the frontdoor? I have no way to figure out the Auth provider which is sending the Auth.UserData through for each claim in apex. Yes, if the payload has a flag (provider name) - then I can use SOQL but this is not ideal since it would have to be sent as a custom attribute for me to utulize on each provider and future providers using this handler.