Search in sources :

Example 1 with JwkKeys

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;
}
Also used : SignedJwt(io.helidon.security.jwt.SignedJwt) Jwt(io.helidon.security.jwt.Jwt) JwkKeys(io.helidon.security.jwt.jwk.JwkKeys) SignedJwt(io.helidon.security.jwt.SignedJwt)

Example 2 with JwkKeys

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"));
}
Also used : SignedJwt(io.helidon.security.jwt.SignedJwt) Jwt(io.helidon.security.jwt.Jwt) JwkKeys(io.helidon.security.jwt.jwk.JwkKeys) SignedJwt(io.helidon.security.jwt.SignedJwt) HelidonTest(io.helidon.microprofile.tests.junit5.HelidonTest) Test(org.junit.jupiter.api.Test)

Aggregations

Jwt (io.helidon.security.jwt.Jwt)2 SignedJwt (io.helidon.security.jwt.SignedJwt)2 JwkKeys (io.helidon.security.jwt.jwk.JwkKeys)2 HelidonTest (io.helidon.microprofile.tests.junit5.HelidonTest)1 Test (org.junit.jupiter.api.Test)1