Spring Boot – How to solve OAuth2 REDIRECT_URI_MISMATCH
ADVERTISEMENT
Table of Contents
Introduction
When trying to authenticate a user using OAuth2 through a third-party service like (Google, Facebook .. etc.), the following error occurs:
Solution
redirect_uri_mismatch error occurs when the redirect URL defined for your application at the authorization service doesn’t match with the value of parameter “redirect_uri” passed by your request.
When integrating OAuth2 with Spring Boot, the default value of redirect_uri is set to “
In order to solve this issue, you have 2 options:
- Define “
: /login” as a redirect URL under the authorization service. - Use a custom redirect URL through 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”.
Summary
When trying to authenticate a user using OAuth2 through a third-party service like (Google, Facebook .. etc.), the following error occurs:
Next Steps
If you're interested in learning more about the basics of Java, coding, and software development, check out our Coding Essentials Guidebook for Developers, where we cover the essential languages, concepts, and tools that you'll need to become a professional developer.
Thanks and happy coding! We hope you enjoyed this article. If you have any questions or comments, feel free to reach out to jacob@initialcommit.io.
Final Notes
Recommended product: Coding Essentials Guidebook for Developers