Home > Software design >  AWS cognito for authentication using vert.x framework in Java
AWS cognito for authentication using vert.x framework in Java

Time:05-24

I want to implement authentication mechanism for my application and also secure my api's using AWS cognito with vert.x framework in Java. Is there any demo or examples of AWS cognito authentication/Authorization implementation since there isn't much on internet about vert.x implementation of cognito(AmazonCognitoAuth) in java? Please do mention code samples.

CodePudding user response:

AWS Cognito is a Oauth2 IdP, so you can use vert.x auth to perform any security checks. There is a helper to Cognito in vert.x too, so creating a new authentication provider can be done as:

AmazonCognitoAuth.discover(
  rule.vertx(),
  new OAuth2Options()
    .setSite("https://cognito-idp.eu-central-1.amazonaws.com/{tenant}")
    .setClientId("the-client-id")
    .setClientSecret("the-client-secret")
    .setTenant("user-pool-id"))
  .onSuccess(oauth2 -> {
    // your oauth2 provider is properly configured
    // you can use it in your application
  });

In order to build a full application I'd recommend you to have a quick read at: https://how-to.vertx.io/web-and-oauth2-oidc/ In that how-to the basics of vert.x Oauth2/OIDC are explained.

  • Related