use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class MultipartRequestTest method shouldNotOverrideContentTypeHeader.
@Test
public void shouldNotOverrideContentTypeHeader() throws Exception {
MultipartBody.Builder bodyBuilder = new MultipartBody.Builder("5c49fdf2");
MultipartRequest<TokenHolder> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", new ObjectMapper(), tokenHolderType, bodyBuilder);
request.addPart("non_empty", "body");
request.addHeader("Content-Type", "plaintext");
server.jsonResponse(AUTH_TOKENS, 200);
request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getHeader("Content-Type"), is("multipart/form-data; boundary=5c49fdf2"));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class MultipartRequestTest method shouldParseJSONErrorResponseWithDescription.
@Test
public void shouldParseJSONErrorResponseWithDescription() throws Exception {
MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
request.addPart("non_empty", "body");
server.jsonResponse(AUTH_ERROR_WITH_DESCRIPTION, 400);
Exception exception = null;
try {
request.execute();
server.takeRequest();
} catch (Exception e) {
exception = e;
}
assertThat(exception, is(notNullValue()));
assertThat(exception, is(instanceOf(APIException.class)));
assertThat(exception.getCause(), is(nullValue()));
assertThat(exception.getMessage(), is("Request failed with status code 400: The user already exists."));
APIException authException = (APIException) exception;
assertThat(authException.getDescription(), is("The user already exists."));
assertThat(authException.getError(), is("user_exists"));
assertThat(authException.getStatusCode(), is(400));
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class TokenRequestTest method setUp.
@Before
public void setUp() throws Exception {
client = new OkHttpClient();
server = new MockServer();
}
use of com.auth0.json.mgmt.client.Client in project auth0-java by auth0.
the class TokenRequestTest method shouldCreateRequest.
@Test
public void shouldCreateRequest() throws Exception {
TokenRequest request = new TokenRequest(client, server.getBaseUrl());
request.addParameter("non_empty", "body");
assertThat(request, is(notNullValue()));
server.jsonResponse(AUTH_TOKENS, 200);
TokenHolder response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest.getMethod(), is("POST"));
assertThat(response, is(notNullValue()));
}
use of com.auth0.json.mgmt.client.Client in project drug-formulary-ri by HL7-DaVinci.
the class AuthUtils method authCodeIsValid.
/**
* Verify the authorization code provided in the POST request's claim to /token
* path
*
* @param code - the authorization code provided in the request
* @param baseUrl - this server base URL
* @param redirectURI - the requestor/client redirect URI provided in the POST
* request
* @param clientId - the client ID retrieved from the request's Authorization
* Header
* @return patientId if the authorization code is valid, otherwise null
*/
public static String authCodeIsValid(String code, String baseUrl, String redirectURI, String clientId) {
String patientId = null;
try {
Algorithm algorithm = Algorithm.RSA256(OauthEndpointController.getPublicKey(), null);
JWTVerifier verifier = JWT.require(algorithm).withIssuer(baseUrl).withAudience(baseUrl).withClaim(REDIRECT_URI_KEY, redirectURI).withClaim(CLIENT_ID_KEY, clientId).build();
DecodedJWT jwt = verifier.verify(code);
String username = jwt.getClaim("username").asString();
User user = User.getUser(username);
patientId = user != null ? user.getPatientId() : null;
} catch (SignatureVerificationException | InvalidClaimException e) {
logger.log(Level.SEVERE, "TokenEndpoint::Authorization code is invalid: Signature invalid or claim value invalid", e);
} catch (AlgorithmMismatchException e) {
logger.log(Level.SEVERE, "TokenEndpoint::Authorization code is invalid: Algorithm mismatch", e);
} catch (TokenExpiredException e) {
logger.log(Level.SEVERE, "TokenEndpoint::Authorization code is invalid: Token expired", e);
} catch (JWTVerificationException e) {
logger.log(Level.SEVERE, "TokenEndpoint::Authorization code is invalid: Please obtain a new code", e);
}
return patientId;
}
Aggregations