use of org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant in project cxf by apache.
the class AuthorizationCodeGrantService method createGrant.
protected Response createGrant(OAuthRedirectionState state, Client client, List<String> requestedScope, List<String> approvedScope, UserSubject userSubject, ServerAccessToken preauthorizedToken) {
// in this flow the code is still created, the preauthorized token
// will be retrieved by the authorization code grant handler
ServerAuthorizationCodeGrant grant = null;
try {
grant = getGrantRepresentation(state, client, requestedScope, approvedScope, userSubject, preauthorizedToken);
} catch (OAuthServiceException ex) {
return createErrorResponse(state.getState(), state.getRedirectUri(), OAuthConstants.ACCESS_DENIED);
}
String grantCode = processCodeGrant(client, grant.getCode(), grant.getSubject());
if (state.getRedirectUri() == null) {
OOBAuthorizationResponse bean = new OOBAuthorizationResponse();
bean.setClientId(client.getClientId());
bean.setClientDescription(client.getApplicationDescription());
bean.setAuthorizationCode(grantCode);
bean.setUserId(userSubject.getLogin());
bean.setExpiresIn(grant.getExpiresIn());
return deliverOOBResponse(bean);
} else if (isFormResponse(state)) {
FormAuthorizationResponse bean = new FormAuthorizationResponse();
bean.setAuthorizationCode(grantCode);
bean.setExpiresIn(grant.getExpiresIn());
bean.setState(state.getState());
bean.setRedirectUri(state.getRedirectUri());
return createHtmlResponse(bean);
} else {
// return the code by appending it as a query parameter to the redirect URI
UriBuilder ub = getRedirectUriBuilder(state.getState(), state.getRedirectUri());
ub.queryParam(OAuthConstants.AUTHORIZATION_CODE_VALUE, grantCode);
return Response.seeOther(ub.build()).build();
}
}
Aggregations