Search code examples
javaspring-bootoauthspring-resource-serverspring-boot-oauth2.1

Is there any listener for the OAuth2 resource server's successful authentication?


Is there any listener for the OAuth2 resource server's successful authentication?

I need, to create/replicate the user details in the spring boot resource server on successful authentication, or during token validation.

Any suggestions, on how to implement it in spring boot?


Solution

  • @Component AuthenticationSuccessEvent event listener works....

    @Component
    public class AuthenticationEvent {
    
        Logger logger = LoggerFactory.getLogger(AuthenticationEvent.class);
    
        @EventListener
        public void onSuccess(AuthenticationSuccessEvent success) {
            System.out.println("S "+ success);
        }
    }
    

    Refer : https://docs.spring.io/spring-security/reference/servlet/authentication/events.html#servlet-events

    &

    Example : https://github.com/m-thirumal/oauth-resource-server/blob/main/src/main/java/in/thirumal/listener/AuthenticationEvent.java