Skip to content

Commit

Permalink
Additional Auth0Service logging (#707)
Browse files Browse the repository at this point in the history
* Adds logging for JWKS retrieval
* Include appBuild in bootstrap banner

---------

Co-authored-by: Don Le <[email protected]>
  • Loading branch information
amcclain and minusleaf authored Mar 18, 2024
1 parent 6c05cf7 commit 2353b6a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion grails-app/init/io/xh/toolbox/BootStrap.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class BootStrap {
\\ \\_\\ \\ \\_____\\ \\ \\_____\\ \\ \\_____\\ \\ \\_____\\ \\ \\_____\\ /\\_\\/\\_\\
\\/_/ \\/_____/ \\/_____/ \\/_____/ \\/_____/ \\/_____/ \\/_/\\/_/
\n
${appName} v${appVersion} - ${appEnvironment}
${appName} v${appVersion} [build ${appBuild}] - ${appEnvironment}
\n
""")
}
Expand Down
26 changes: 15 additions & 11 deletions grails-app/services/io/xh/toolbox/security/Auth0Service.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Auth0Service extends BaseService {
JwtValidationResult validateToken(String token) {
try {
if (!token) throw new JwtException("Unable to validate JWT - no token provided.")
logTrace("Validating token", token)

def jws = new JsonWebSignature()
jws.setCompactSerialization(token)
Expand All @@ -53,16 +54,17 @@ class Auth0Service extends BaseService {
if (!jws.verifySignature()) throw new JwtException("Token failed signature validation")

def payload = JSONParser.parseObject(jws.payload)
if (payload.aud != this.clientId) {
if (payload.aud != clientId) {
throw new JwtException("Token aud value [${payload.aud}] does not match expected value from auth0ClientId config.")
}

logDebug(["Token validated successfully", [sub: payload.sub, email: payload.email, fullName: payload.name]])
return new JwtValidationResult(
token: token,
sub: payload.sub,
email: payload.email,
fullName: payload.name,
profilePicUrl: payload.picture
token: token,
sub: payload.sub,
email: payload.email,
fullName: payload.name,
profilePicUrl: payload.picture
)

} catch (e) {
Expand All @@ -83,13 +85,15 @@ class Auth0Service extends BaseService {

private JsonWebKeySet _jwks
JsonWebKeySet getJsonWebKeySet() {
def url = "https://${domain}/.well-known/jwks.json"
if (!_jwks) {
def url = "https://${domain}/.well-known/jwks.json",
jwksJson = client.executeAsString(new HttpGet(url))
_jwks = new JsonWebKeySet(jwksJson)
withInfo(["Fetching JWKS", url]) {
def jwksJson = client.executeAsString(new HttpGet(url))
_jwks = new JsonWebKeySet(jwksJson)

if (!_jwks.jsonWebKeys.size()) {
throw new RuntimeException("Unable to build valid key set from remote JWKS endpoint.")
if (!_jwks.jsonWebKeys.size()) {
throw new RuntimeException("Unable to build valid key set from remote JWKS endpoint.")
}
}
}

Expand Down

0 comments on commit 2353b6a

Please sign in to comment.