Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 978 Bytes

README.md

File metadata and controls

28 lines (20 loc) · 978 Bytes

scalecube-security

Codacy Badge

JWT authentication basic usage

Given a JWT we would like to authenticate it and extract its claims:

Generating JWT for example:

String hmacSecret = "secert";

String token = Jwts.builder().setAudience("anAudience")
                .setSubject("aSubject")
                .signWith(SignatureAlgorithm.HS256, hmacSecret.getBytes())
                .compact();

Authenticating the JWT:

JwtAuthenticator authenticator = new JwtAuthenticatorImpl
                .Builder()
                .keyResolver(map -> Optional.of(new SecretKeySpec(hmacSecret.getBytes(), "HMACSHA256")))
                .build();
                
Profile profile = authenticator.authenticate(token)