I'm a bit confused regarding whether I should be accessing my Spring Boot Resource Server via an access_token or an id_token.
First, let me quickly explain my setup:
- Spring Boot app as an OAuth 2.0 Resource Server. This is configured as described in the Spring docs: Minimal Configuration for JWTs This app provides secured @Controllers that will provide data for a JavaScript SPA (eg. React)
- Google's OAuth 2.0 AP / OpenID Connect already configured (Credentials, Client Id, Client Secret)
- A JavaScript SPA app (eg. React) that logs the user into Google and makes requests to the Spring Boot Resource Server for secured data. These requests include the Authorization header (with Bearer token obtained from Google) for the logged in user.
- For development purposes, I'm also using Postman to make requests to the Spring Boot Resource Server
I can easily configure Postman to get a token from Google. This token response from Google includes values for access_token
, id_token
, scope
, expries_in
and token_type
.
However, my requests to the Resource Server are denied when Postman tries to use the value from retrieved token's access_token
field as the Bearer in the Authorization header
The only way I'm able to successfully access the secured @Controllers
is by using the id_token
as the Bearer in the Authorization header.
Is it expected that I should use the id_token
as the Bearer in the Authorization header? Or is it expected that I should use the access_token
?
Some additional relevant info:
- The value of the
id_token
is a JWT token. The value of theaccess_token
is not a JWT token. I know this because I can decode theid_token
on jwt.io but it is unable to decode the value of theaccess_token
. Further, the Spring Boot Resource Server fails with the following when I send theaccess_token
as the Bearer in the Authorization header:
An error occurred while attempting to decode the Jwt: Invalid unsecured/JWS/JWE header: Invalid JSON: Unexpected token ɭ� at position 2.
- This blog post Understanding identity tokens says the following:
You should not use an identity token to authorize access to an API. To access an API, you should be using OAuth’s access tokens, which are intended only for the protected resource (API) and come with scoping built-in.
- Looking at at the spring-security-samples for using OAuth2 Resource Server, I see the value of there hard-coded
access_token
(for testing purposes) is indeed a valid JWT. As opposed to theaccess_token
returned from Google which is not a JWT.
In summary:
- I can access my Spring Boot Resource Server using the value of the
id_token
obtained from Google. The value of theaccess_token
is not a JWT and fails to parse by Spring Boot. - Is there something wrong with my understanding, my configuration or what? Does Google's OpenId Connect behave differently regarding how the
access_token
works?
Happy to clarify or add more info if needed. Thanks for your consideration and your patience!