Book Image

OAuth 2.0 Cookbook

By : Adolfo Eloy Nascimento
Book Image

OAuth 2.0 Cookbook

By: Adolfo Eloy Nascimento

Overview of this book

OAuth 2.0 is a standard protocol for authorization and focuses on client development simplicity while providing specific authorization flows for web applications, desktop applications, mobile phones, and so on. This book also provides useful recipes for solving real-life problems using Spring Security and creating Android applications. The book starts by presenting you how to interact with some public OAuth 2.0 protected APIs such as Facebook, LinkedIn and Google. You will also be able to implement your own OAuth 2.0 provider with Spring Security OAuth2. Next, the book will cover practical scenarios regarding some important OAuth 2.0 profiles such as Dynamic Client Registration, Token Introspection and how to revoke issued access tokens. You will then be introduced to the usage of JWT, OpenID Connect, and how to safely implement native mobile OAuth 2.0 Clients. By the end of this book, you will be able to ensure that both the server and client are protected against common vulnerabilities.
Table of Contents (16 chapters)
Title Page
About the Author
About the Reviewer
Customer Feedback

Accessing an OAuth 2.0 protected API with RestTemplate

This recipe is useful when you don't have Spring Security OAuth2 in your project but are still using the Spring Framework. Instead of using OAuth2RestTemplate, this recipe shows you how to use raw RestTemplate implementation to interact with any OAuth 2.0 Provider.

Getting ready

To run this recipe, make sure you have an OAuth 2.0 Provider running on your machine. I recommend you use the project auth-code-server presented in Chapter 2, Implementing Your Own OAuth 2.0 Provider. If you have any doubts about the source code presented in this recipe, do not hesitate to download the source code available on GitHub at Besides having an OAuth 2.0 Provider running, you will need Java 8, Maven, and your preferred IDE (remember that most examples are presented using Eclipse).

How to do it...

The next steps show you how to create a client application that...