[SalesForce] How to get refresh token on the page using USER AGENT flow of salesforce

I am a beginner in Angular JS and Salesforce.

I am building a hybrid application.

I am using the USER AGENT authentication flow

I used the following url :

https://login.salesforce.com/services/oauth2/authorize?response_type=token&client_id=consumer_key&redirect_uri=https://localhost:63342/www/index.html#/

I got the result as expected with the access token but did not get the refresh token.

Then i found this

The refresh token is only returned if the redirect URI is https://login.salesforce.com/services/oauth2/success or used with a custom protocol that is not HTTPS.

So I changed the redirect_uri in my url as :

https://login.salesforce.com/services/oauth2/authorize?response_type=token&client_id=3MVG9ZL0ppGP5UrCf3JELrQofxTN1p28Y0qBjNy67uUtwoVl8i0LX6ntfchfUlDJoeso1xKRxGHx_Tzk_SAiK&redirect_uri=https://login.salesforce.com/services/oauth2/success

I got the refresh token.

But then the page is stuck up at the below link

https://login.salesforce.com/services/oauth2/success#access_token=access_token&refresh_token=refresh_token&instance_url=https%3A%2F%2Fap2.salesforce.com&id=id&issued_at=1444119251446&signature=sign&scope=scope&token_type=Bearer

How do i make it redirect back to my app link

https://localhost:63342/www/index.html#/

Thanks in advance.

Best Answer

I got the Answer.

I just changed the callback url in connected app settings to my app url and we have to use http instead of https.

Related Topic