0

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?

Thirumal
  • 8,280
  • 11
  • 53
  • 103
  • This has been answered here: https://stackoverflow.com/questions/59873571/spring-boot-what-event-fired-during-oauth2-authorization-success – Mar-Z Mar 20 '23 at 11:29
  • I tried, but that didn't work with version 3.0.3.. – Thirumal Mar 20 '23 at 12:02

1 Answers1

0

@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

Thirumal
  • 8,280
  • 11
  • 53
  • 103