3

Background:

I have created a custom Auth. Provider in Salesforce to reach out to an authorization server that isn't on the default list of Provider Types. I used https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/authproviderplugin.htm as a good starting point to extend the Auth.AuthProviderPluginClass. Once appropriately added to my org, it then became an option on the list of Provider Types. I was able to create an Auth. Provider using that new provider type and it works to initiate the OAuth2.0 flow. I am appropriately able to get the access token and refresh token from the authorization server.

The Problem:

As it currently stands, we will have users click on a button that will send them to the provided "OAuth-Only Initialization URL" link that was generated when I created the actual Auth. Provider record. The trick is that when the OAuth2.0 flow is completed, the user is redirected back to the Salesforce Setup Home page, and I don't see a good way in the documentation to override the final destination to be something else (like a success page or something).

Question:

Does anyone know of a way to override the final destination of the OAuth2.0 flow from a custom OAuth2.0 Auth provider?


UPDATE: I tried using the startUrl (and also tried retUrl for good measure) as query params, but doing so didn't change the behavior after the OAuth2.0 flow finished.

Meaning, both of the following URLs gave me the same final destination as not having any query params at all:

https://<scratch org random url>.my.salesforce.com/services/auth/oauth/MyCustomAuthProvider?retUrl=lightning%2Fpage%2Fhome
https://<scratch org random url>.my.salesforce.com/services/auth/oauth/MyCustomAuthProvider?startUrl=lightning%2Fpage%2Fhome

Another Update: This WORKED:

https:/<scratch org random url>.my.salesforce.com/services/auth/oauth/MyCustomAuthProvider?startURL=%2Flightning%2Fn%2FCustomPage

Apparently, it was important to add the leading /, (of course, url encoded to be %2F) and %2Flightning%2Fpage%2Fhome gets interpreted as the setup home and sends you there.


(Parallel posted to Salesforce Dev Forum: https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_DETAIL&id=9062I000000gAPyQAM)

1 Answer 1

0

Append startURL as a query parameter to the oAuth-only initialization URL. The value of this parameter should be a URL-encoded destination of where you want the user to land. See docs for more info.

5
  • identigral, thank you for the response, but trying what you suggested didn't work for me. Could you take a look at my update and let me know if you have something you would recommend I try instead? Commented Aug 30, 2019 at 0:00
  • identigral, I figured it out and you were right. I updated my question to show what I did. Commented Aug 30, 2019 at 18:24
  • This doesn't work for Visualforce or Lightning URLs. Commented Mar 21, 2022 at 9:13
  • 1
    @Robert Sösemann Works for us. Please post a new question if you're running into an issue.
    – identigral
    Commented Mar 21, 2022 at 9:15
  • @identigral I added my new question here salesforce.stackexchange.com/q/371991/256 Commented Mar 21, 2022 at 9:28

You must log in to answer this question.

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