I am trying to understand why anonymous users in the client can't get an access token.
I found this post on the Spring Blog regarding this topic, where Dave Syer answers this:
Remember this is an issue to do with the client app, not the auth server, so try and see it from the point of view of the cllient. At step 1. there is a user trying to access a protected resource. If you can't idenitify that user then all your users end up with the same access token (the one that the first user obtains using his credentials at the auth server). This is definitely a bad idea.
However I don't see why anonymous users would share the same token:
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth instanceof AnonymousAuthenticationToken) {
if (!resource.isClientOnly()) {
throw new InsufficientAuthenticationException(
"Authentication is required to obtain an access token (anonymous not allowed)");
}
}
Although they are not fully authenticated, they have a JSESSIONID bound to every individual anonymous user.
The OAuth2ClientContext, which would contain the accessToken, is a session scoped Spring bean. Since anonymous users have a HttpSession they have independent OAuth2ClientContexts so they could store individual accessTokens.
Could someone explain if this makes sense or what I am not understanding?