use of org.orcid.core.oauth.OAuthError in project ORCID-Source by ORCID.
the class OauthGenericCallsController method obtainOauth2TokenPost.
@RequestMapping(value = "/oauth/token", consumes = MediaType.APPLICATION_FORM_URLENCODED, produces = MediaType.APPLICATION_JSON)
public ResponseEntity<?> obtainOauth2TokenPost(HttpServletRequest request) {
String authorization = request.getHeader("Authorization");
Enumeration<String> paramNames = request.getParameterNames();
MultivaluedMap<String, String> formParams = new MultivaluedMapImpl();
while (paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
formParams.add(paramName, request.getParameter(paramName));
}
try {
Response response = orcidClientCredentialEndPointDelegator.obtainOauth2Token(authorization, formParams);
return ResponseEntity.ok(response.getEntity());
} catch (Exception e) {
OAuthError error = OAuthErrorUtils.getOAuthError(e);
HttpStatus status = HttpStatus.valueOf(error.getResponseStatus().getStatusCode());
return ResponseEntity.status(status).body(error);
}
}
use of org.orcid.core.oauth.OAuthError in project ORCID-Source by ORCID.
the class OauthGenericCallsControllerTest method testObtainOauth2TokenPostLockedClient.
@Test
public void testObtainOauth2TokenPostLockedClient() {
when(orcidClientCredentialEndPointDelegator.obtainOauth2Token(isNull(), any())).thenThrow(new LockedException("Client is locked"));
ResponseEntity<?> responseEntity = controller.obtainOauth2TokenPost(new MockHttpServletRequest());
assertNotNull(responseEntity);
assertNotNull(responseEntity.getBody());
assertTrue(responseEntity.getBody() instanceof OAuthError);
OAuthError error = (OAuthError) responseEntity.getBody();
assertEquals(OAuthError.UNAUTHORIZED_CLIENT, error.getError());
assertEquals("Client is locked", error.getErrorDescription());
}
Aggregations