Loading

OAuth 2.0 Dance (Authorize) Fails With Error "redirect_uri_mismatch"

Date de publication: Mar 2, 2024
Résolution

SYMPTOM

You are using OAuth 2.0 authentication in your Mule application and performing OAuth dance by invoking Authorize URL configured in the OAuth 2.0 configuration in your application.
In this example, the authorization URL is invoked from the browser:

invoke_authorize_url.png

However you are seeing the following error response.
error while authorizing:: error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration

e.g., Salesforce OAuth 2.0 dance throwing "redirect_uri_mismatch" error.
redirect_uri_mismatch

CAUSE

When reviewing the application logs, you will see the redirect URI is invoked to pass the access token to the Callback URL.
[2021-10-15 10:54:55.111] DEBUG   org.mule.service.http.impl.service.HttpMessageLogger.HTTP_Listener_config [http.listener.01 SelectorRunner]: LISTENER
HTTP/1.1 302 Moved Temporarily
Content-Length: 0
location: https://test.my.salesforce.com/services/oauth2/authorize?response_type=code&client_id=.....&redirect_uri=https%3A%2F%2Ftest-salesforce.us-e2.cloudhub.io%2Fapi%2FcompositeCallback
After authorizing the client, the Authorization server invokes the callback URL to pass the access token and refresh tokens. This is configured in the "oauthCallbackConfig" of your application, e.g.,
callback_url_config_mule

However, in this case, the callback URL configured in the server is different from the URL configured in your Mule application resulting in the Redirect URI Mismatch error.

SOLUTION

In order to resolve this issue, you need to ensure that the OAuth 2.0 callback URL configured in your server should match with the URL where your application is configured. Once configured in your "oauthCallbackConfig", callback URL will implicitly create an endpoint listening to this URL. Based on the type of deployment, you need to ensure that the whole URL should be configured in the server's OAuth 2.0 client application config, e.g.,
callback_url_config_server

And the OAuth dance will succeed.
callback_url_success  
Numéro d’article de la base de connaissances

001122778

 
Chargement
Salesforce Help | Article