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{ JsonObject o = json.asJsonObject(); throw new OAuth2InternalServerException(e.getMessage()); throw new OAuth2InternalServerException("Invalid response from auth server");
protected void refreshJwtVerifier() { log.info("Fetching public key from server, url '{}' ...", config.getPublicKeyUrl()); HttpResponse response = httpClient.request(config.getPublicKeyUrl()).get(); if(!response.isOk()) { throw new OAuth2InternalServerException("Error fetching public key from server, status " + response.getStatus() + ""); } String encoded = response.getString(); RSAPublicKey publicKey = RSA.decodePublicKey(encoded); verifier = new RsaVerifier(publicKey); }
throw new OAuth2InternalServerException("Invalid response from auth server : not a json map"); }else{ Map<String, Object> map = json.asMap(); throw new OAuth2ResponseException(response.getStatus(),error, desc); }else { throw new OAuth2InternalServerException("Auth server response error '" + error + "' : " + desc); throw new OAuth2InternalServerException("Invalid response from auth server");