/** * Parse the json string and returns the the array. */ public static Map<String,Object> decodeMap(String json){ return parse(json).asMap(); }
protected Map<String, Object> verify(String content, String payload, String signature) { if (!verifySignature(content, signature)) { throw new TokenVerifyException(ErrorCode.INVALID_SIGNATURE, "Signature verification failed"); } JsonValue json; try { json = JSON.parse(JWT.base64UrlDeocodeToString(payload)); } catch (Exception e) { throw new TokenVerifyException(ErrorCode.INVALID_PAYLOAD, "Parse payload as json object failed, " + e.getMessage()); } if (!json.isMap()) { throw new TokenVerifyException(ErrorCode.INVALID_PAYLOAD, "The payload must be json object '{..}'"); } //get claims Map<String, Object> claims = json.asMap(); //verify expiration verifyExpiration(claims); return claims; }
protected AccessToken fetchAccessToken(HttpRequest request) { if(null != config.getClientId()){ request.addHeader(Headers.AUTHORIZATION, "Basic " + Base64.encode(config.getClientId()+":"+config.getClientSecret())); } HttpResponse response = request.send(); if(ContentTypes.APPLICATION_JSON_TYPE.isCompatible(response.getContentType())){ String content = response.getString(); log.debug("Received response : {}", content); JsonValue json = JSON.parse(content); if(!json.isMap()) { throw new OAuth2InternalServerException("Invalid response from auth server : not a json map"); }else{ Map<String, Object> map = json.asMap(); String error = (String)map.get("error"); if(Strings.isEmpty(error)) { return createAccessToken(map); }else{ throw new OAuth2InternalServerException("Auth server response error '" + error + "' : " + map.get("error_description")); } } }else{ throw new OAuth2InternalServerException("Invalid response from auth server"); } }
throw new OAuth2InternalServerException("Invalid response from auth server : not a json map"); }else{ Map<String, Object> map = json.asMap(); String error = (String)map.get("error"); if(Strings.isEmpty(error)) {
throw new OAuth2InternalServerException("Invalid response from auth server : not a json map"); }else{ Map<String, Object> map = json.asMap(); String error = (String)map.get("error"); if(Strings.isEmpty(error)) {