codeReg.setApprovedScope(approvedScope);
codeReg.setSubject(userSubject);
codeReg.setAudience(params.getFirst(OAuthConstants.CLIENT_AUDIENCE));
codeReg.setClientCodeVerifier(params.getFirst(OAuthConstants.AUTHORIZATION_CODE_VERIFIER));
ServerAuthorizationCodeGrant grant = null;
try {
grant = ((AuthorizationCodeDataProvider)getDataProvider()).createCodeGrant(codeReg);
} catch (OAuthServiceException ex) {
return createErrorResponse(params, redirectUri, OAuthConstants.ACCESS_DENIED);
}
if (redirectUri == null) {
OOBAuthorizationResponse oobResponse = new OOBAuthorizationResponse();
oobResponse.setClientId(client.getClientId());
oobResponse.setAuthorizationCode(grant.getCode());
oobResponse.setUserId(userSubject.getLogin());
oobResponse.setExpiresIn(grant.getExpiresIn());
return deliverOOBResponse(oobResponse);
} else {
// return the code by appending it as a query parameter to the redirect URI
UriBuilder ub = getRedirectUriBuilder(params.getFirst(OAuthConstants.STATE), redirectUri);
ub.queryParam(OAuthConstants.AUTHORIZATION_CODE_VALUE, grant.getCode());
return Response.seeOther(ub.build()).build();
}
}