use of io.helidon.security.jwt.jwk.JwkKeys in project helidon by oracle.
the class Mp1Main method generateJwtToken.
private static String generateJwtToken() {
Jwt jwt = Jwt.builder().subject("jack").addUserGroup("admin").addScope("admin_scope").algorithm(JwkRSA.ALG_RS256).issuer("native-image-mp1").audience("http://localhost:8087/jwt").issueTime(Instant.now()).userPrincipal("jack").keyId("SIGNING_KEY").expirationTime(Instant.now().plus(5, ChronoUnit.MINUTES)).build();
JwkKeys jwkKeys = JwkKeys.builder().resource(Resource.create("sign-jwk.json")).build();
SignedJwt signed = SignedJwt.sign(jwt, jwkKeys.forKeyId("sign-rsa").get());
String tokenContent = signed.tokenContent();
System.out.println("JWT token to use for /jwt requests: " + tokenContent);
return tokenContent;
}
use of io.helidon.security.jwt.jwk.JwkKeys in project helidon by oracle.
the class Gh3246Test method testSecuredCallout.
@Test
void testSecuredCallout() {
Jwt jwt = Jwt.builder().subject("jack").addUserGroup("admin").algorithm(JwkRSA.ALG_RS256).issuer("test-gh-3246").audience("http://example.helidon.io").issueTime(Instant.now()).userPrincipal("jack").keyId("SIGNING_KEY").build();
JwkKeys jwkKeys = JwkKeys.builder().resource(Resource.create("sign-jwk.json")).build();
SignedJwt signed = SignedJwt.sign(jwt, jwkKeys.forKeyId("sign-rsa").get());
String tokenContent = signed.tokenContent();
int port = webTarget.getUri().getPort();
String response = webTarget.path("/test/secured").queryParam("port", port).request().header(Http.Header.AUTHORIZATION, "Bearer " + tokenContent).get(String.class);
assertThat(response, is("hello"));
}
Aggregations