diff options
Diffstat (limited to 'vespa-athenz')
-rw-r--r-- | vespa-athenz/pom.xml | 12 | ||||
-rw-r--r-- | vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/AthenzAccessToken.java | 9 |
2 files changed, 20 insertions, 1 deletions
diff --git a/vespa-athenz/pom.xml b/vespa-athenz/pom.xml index 0f23eaed964..7d2ad924ae3 100644 --- a/vespa-athenz/pom.xml +++ b/vespa-athenz/pom.xml @@ -131,7 +131,17 @@ <artifactId>jackson-annotations</artifactId> </exclusion> </exclusions> - </dependency> + </dependency> + <dependency> + <groupId>com.auth0</groupId> + <artifactId>java-jwt</artifactId> + <exclusions> + <exclusion> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + </exclusion> + </exclusions> + </dependency> </dependencies> <build> diff --git a/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/AthenzAccessToken.java b/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/AthenzAccessToken.java index 49b10a37329..7ad97f8ac3c 100644 --- a/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/AthenzAccessToken.java +++ b/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/api/AthenzAccessToken.java @@ -1,6 +1,10 @@ // Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.athenz.api; +import com.auth0.jwt.JWT; +import com.auth0.jwt.interfaces.DecodedJWT; + +import java.time.Instant; import java.util.Objects; /** @@ -15,9 +19,11 @@ public class AthenzAccessToken { private static final String BEARER_TOKEN_PREFIX = "Bearer "; private final String value; + private final DecodedJWT jwt; public AthenzAccessToken(String value) { this.value = stripBearerTokenPrefix(value); + this.jwt = JWT.decode(this.value); } private static String stripBearerTokenPrefix(String rawValue) { @@ -33,6 +39,9 @@ public class AthenzAccessToken { public String value() { return value; } public String valueWithBearerPrefix() { return BEARER_TOKEN_PREFIX + value; } + public Instant getExpiryTime () { + return jwt.getExpiresAt().toInstant(); + } @Override public String toString() { return "AthenzAccessToken{value='" + value + "'}"; } |