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

290 views Asked by At

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?

1

There are 1 answers

0
Thirumal On BEST ANSWER

@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