@Override
  public Object decodeToken(final String token) {

    final JWTVerifier jwtVerifier = new JWTVerifier(clientSecret, clientId);

    Map<String, Object> verify;
    try {

      verify = jwtVerifier.verify(token);
      final String payload = (String) verify.get("$");
      @SuppressWarnings("unchecked")
      final Map<String, String> map = new ObjectMapper().readValue(payload, Map.class);
      return map;

    } catch (final InvalidKeyException e) {
      throw new Auth0RuntimeException(e);
    } catch (final NoSuchAlgorithmException e) {
      throw new Auth0RuntimeException(e);
    } catch (final IllegalStateException e) {
      throw new Auth0RuntimeException(e);
    } catch (final SignatureException e) {
      throw new Auth0RuntimeException(e);
    } catch (final IOException e) {
      throw new Auth0RuntimeException(e);
    }
  }
Example #2
0
 @Override
 public Long readUserIdFromToken(String token) {
   Long id = null;
   try {
     Map<String, Object> parsed = verifier.verify(token);
     Object objectId = parsed.get("id");
     if (objectId instanceof Integer) {
       id = Long.valueOf((Integer) objectId);
     } else if (objectId instanceof Long) {
       id = (Long) objectId;
     } else if (objectId instanceof String) {
       id = Long.valueOf((String) objectId);
     }
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (InvalidKeyException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (SignatureException e) {
     e.printStackTrace();
   } catch (JWTVerifyException e) {
     e.printStackTrace();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return id;
 }
  @Override
  public void process(Request request) {
    if (request.isFlagged(Flags.Auth.PUBLIC_ROUTE)
        || request.isFlagged(Flags.Auth.NO_AUTHENTICATION)) return;

    String token = getToken(request);

    try {
      Map<String, Object> decoded = jwtVerifier.verify(token);
      request.putAttachment(AUTH0_JWT, decoded);
    } catch (Exception e) {
      throw new UnauthorizedException("Token validation failed");
    }
  }