Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Spring Boot: Solving OAuth2 REDIRECT_URI_MISMATCH [Snippet]

DZone's Guide to

Spring Boot: Solving OAuth2 REDIRECT_URI_MISMATCH [Snippet]

If you've come across a redirect_uri_mismatch error before when using Spring Boot and OAuth 2, then this solution is for you.

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

Problem: When trying to authenticate a user using OAuth2 through a third-party service like (Google, Facebook, etc.), the following error occurs:

Solution: A redirect_uri_mismatch error occurs when the redirect URL defined for your application at the authorization service doesn't match the value of parameter "redirect_uri" passed by your request.

When integrating with Spring Boot, the default value of redirect_uri is set to "<ip>:<port>/login".

In order to solve this issue, you have 2 options:

  1. Define “<ip>:<port>/login” as a redirect URL under the authorization service.

  2. Use a custom redirect URL by setting the following attributes in application.properties:

security.oauth2.client.preEstablishedRedirectUri=http://localhost:9090/callback
security.oauth2.client.useCurrentUri=false


In the above configuration, we set a custom redirect URI as “http://localhost:9090/callback”.

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. 

Topics:
java ,spring boot ,oauth 2 ,user authentication ,redirect_uri_mismatch error

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}