I am new to Spring Boot and I am developing a simple API with few endpoints. Now I am implementing an Authorization Server (Oauth2AuthorizationServer) and Resource server with my endpoints. I have noticed that when AuthServer issues once a JWT token with provided credentials (I am using credential flow), Resource Server is able to verify the JWT even when the AuthServer is stopped. How that magic happens? I was thinking in the beginning that AuthServer must authorize every request made to the resource server. I can't figure it out how Resource server is able to decode the JWT even the auth server is down. Please, can somebody explain it to me how exactly things work.
When I try to make the first request to Resource server and AuthServer is stopped, there is an error - that there is no @Bean with decoder().
Spring Security supports protecting endpoints by using two forms of OAuth 2.0 Bearer Tokens:
The behavior you experienced means that you configured JWT Authentication, by specifying the Authorization Server with an issuer URI, for example:
According to Spring documentation:
It configures itself through the following steps:
An important note from the docs which answers one of your questions is:
During the runtime, any request containing an
Authorization: Bearer
header is processed as follows:There is no communication between Resource Server and Authorization Server during this process, so it doesn't have to be up after startup.
The behavior you expected, in the beginning, is actually related to Opaque Token Authentication. Where Authorization Server is specified with different properties, according to Spring documentation:
At the runtime, it is also processing any request containing an
Authorization: Bearer
header:This means that the token is valid only if the Authorization Server responds that it is.