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.
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).
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
%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)