We have a working external identity provider SSO Oauth 2.0 with custom apex provider. (External app redirects to a specific SF community) We need to extend it to accept a custom parameter from the incoming url in the initiate() Auth.AuthProviderPluginClass method to be able to redirect the user to a specific record.

URL.getSalesforceBaseUrl() and ApexPages.currentPage().getUrl() are obviously not working.

Is there any way to get the URL parameter in the initiate() method to change the redirect url?

Or is there any way to change the redirect url in the custom handler where we already have the user context? (PageRreference is returned already in the provider, before getting information about the user)

2 Answers 2


You cannot use a custom parameter as this flow is based on oAuth.

The stateToPropagate argument in initiate() is the way to pass information to your plugin. You can then use it to build the target URL,e.g.

public PageReference initiate(Map<String,String> config, String stateToPropagate) {

            final PageReference pageRef = new PageReference(...); 
            return pageRef;

The value of stateToPropagate corresponds to the state query parameter in oAuth flow.


You'll want to see the following two sections of the Salesforce External Identity Implementation Guide:

I think the latter is more specifically what you'll need to do if looking for a redirect parameter. You'll need to store it in something like the Expid, after which you can extend endpoints with either the expid_value or expid={value}.



There's much more in the document you may find helpful as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .