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
Usman ImtiazUsman Imtiaz 

Salesforce oauth redirects to instance url for login


I've a Login with salesforce functionality enabled in my application. When I generate a login oauth url which consists of app secret and ket and after sending a get request using browser It redirects me to a previously used cache instance url.

It should redirect to https://login.salesforce.com/?ec=302&startURL=%2{someurl}

but instead it's redirecting to https://myinstance.salesforce.com/?ec=302&startURL=%2{someurl} although I'm logged out of salesforce and this url only accepts my login credentials which are linked with my instance where as login.salesforce.com accepts anyone's login credentials.

if I use incognito window it works fine and I've even tested the oauth url using postman the response is a html file which has javascript function which redirects to login.salesforce.com/?ec=302&startURL=%2{someurl}
Is there anyway I can solve this issue or force my oauth url to redirect to login.salesforce instead of cached url.
SET Data ImportSET Data Import
we have met the same problem and cannot resolve it either.
For authorization: https://login.salesforce.com/services/oauth2/authorize, the web client will send a request to this uri to get a request code, if no sf account is logged, it will direct the user to https://instance.salesforce.com instead of https://login.salesforce.com.

on different machines, I copied the same uri (https://login.salesforce.com/services/oauth2/authorize?****) into the browser, the redirected login uri is different, could be https://instance.salesforce.com or https://login.salesforce.com.
sky Gongsky Gong
You may add prompt=select_account to your URL, eg:
https://test.salesforce.com/services/oauth2/authorize?response_type=code&client_id=xxx&redirect_uri=xxx&prompt=select_account

For me, it won't redirect to instance URL with this parameter.
Sam HodakSam Hodak
I think I am having a similar version of this issue. After authentication, my browser does not always redirect back to the redirect uri we provided. I think the URI is being overwritten somehow.

Thank you for the suggestion, sky Gong, do you know why prompt=select_account helps?
John James 40John James 40
I think I am having a comparative form of this issue. After confirmation, my program doesn't generally divert back to the divert uri we gave. I think the URI is being overwritten some way or another. https://www.calisontech.com/automobile-displays
John AleyJohn Aley
I think I am having a comparative form of this issue. After verification, my program doesn't consistently divert back to the divert uri we gave. I think the URI is being overwritten some way or another. https://teststripbank.com/

Much obliged to you for the idea, sky Gong, do you have at least some idea why prompt=select_account makes a difference?
May 15, 2020·Like0·Dislike1·Flag
Ali MARZOUKAli MARZOUK
Hey Usman,

I encountred the same problem the solution is in fact to append the prompt parameter to you request url as a parameter. In fact, as stated in the documentation  (https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_web_server_flow.htm&type=5)
"
prompt : Specifies how the authorization server prompts the user for reauthentication and reapproval. Salesforce supports these values.
               login —The authorization server must prompt the user for reauthentication, forcing the user to log in again.
"

So in my case I added the "...&prompt=login" to my authorization URL and it worked perfectly.

Have a good day.