use of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken in project cxf by apache.
the class OAuthJSONProviderTest method doReadClientAccessToken.
@SuppressWarnings({ "unchecked", "rawtypes" })
public ClientAccessToken doReadClientAccessToken(String response, String expectedTokenType, Map<String, String> expectedParams) throws Exception {
OAuthJSONProvider provider = new OAuthJSONProvider();
ClientAccessToken token = (ClientAccessToken) provider.readFrom((Class) ClientAccessToken.class, ClientAccessToken.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(), new ByteArrayInputStream(response.getBytes()));
assertEquals("1234", token.getTokenKey());
assertTrue(expectedTokenType.equalsIgnoreCase(token.getTokenType()));
assertEquals("5678", token.getRefreshToken());
assertEquals(12345, token.getExpiresIn());
assertEquals("read", token.getApprovedScope());
Map<String, String> extraParams = token.getParameters();
if (expectedParams != null) {
assertEquals(expectedParams, extraParams);
}
assertEquals("http://abc", extraParams.get("my_parameter"));
return token;
}
use of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken in project cxf by apache.
the class OAuthJSONProviderTest method testReadHawkClientAccessToken.
@Test
public void testReadHawkClientAccessToken() throws Exception {
String response = "{" + "\"access_token\":\"1234\"," + "\"token_type\":\"hawk\"," + "\"refresh_token\":\"5678\"," + "\"expires_in\":12345," + "\"scope\":\"read\"," + "\"secret\":\"adijq39jdlaska9asud\"," + "\"algorithm\":\"hmac-sha-256\"," + "\"my_parameter\":\"http://abc\"" + "}";
ClientAccessToken macToken = doReadClientAccessToken(response, "hawk", null);
assertEquals("adijq39jdlaska9asud", macToken.getParameters().get(OAuthConstants.HAWK_TOKEN_KEY));
assertEquals("hmac-sha-256", macToken.getParameters().get(OAuthConstants.HAWK_TOKEN_ALGORITHM));
}
use of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken in project cxf by apache.
the class OAuthJSONProviderTest method testWriteHawkClientAccessToken.
@Test
public void testWriteHawkClientAccessToken() throws Exception {
ClientAccessToken token = new ClientAccessToken("hawk", "1234");
token.setExpiresIn(12345);
token.setRefreshToken("5678");
token.setApprovedScope("read");
Map<String, String> params = new LinkedHashMap<String, String>();
params.put(OAuthConstants.HAWK_TOKEN_KEY, "test_mac_secret");
params.put(OAuthConstants.HAWK_TOKEN_ALGORITHM, OAuthConstants.HMAC_ALGO_SHA_1);
params.put("my_parameter", "http://abc");
token.setParameters(params);
OAuthJSONProvider provider = new OAuthJSONProvider();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
provider.writeTo(token, ClientAccessToken.class, ClientAccessToken.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos);
doReadClientAccessToken(bos.toString(), OAuthConstants.HAWK_TOKEN_TYPE, params);
}
use of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken in project cxf by apache.
the class AbstractImplicitGrantService method getClientAccessToken.
protected ClientAccessToken getClientAccessToken(OAuthRedirectionState state, Client client, List<String> requestedScope, List<String> approvedScope, UserSubject userSubject, ServerAccessToken preAuthorizedToken) {
ServerAccessToken token = null;
if (preAuthorizedToken == null) {
AccessTokenRegistration reg = createTokenRegistration(state, client, requestedScope, approvedScope, userSubject);
token = getDataProvider().createAccessToken(reg);
} else {
token = preAuthorizedToken;
if (state.getNonce() != null) {
JAXRSUtils.getCurrentMessage().getExchange().put(OAuthConstants.NONCE, state.getNonce());
}
}
ClientAccessToken clientToken = OAuthUtils.toClientAccessToken(token, isWriteOptionalParameters());
processClientAccessToken(clientToken, token);
return clientToken;
}
use of org.apache.cxf.rs.security.oauth2.common.ClientAccessToken in project cxf by apache.
the class AbstractImplicitGrantService method prepareFormResponse.
protected AbstractFormImplicitResponse prepareFormResponse(OAuthRedirectionState state, Client client, List<String> requestedScope, List<String> approvedScope, UserSubject userSubject, ServerAccessToken preAuthorizedToken) {
ClientAccessToken clientToken = getClientAccessToken(state, client, requestedScope, approvedScope, userSubject, preAuthorizedToken);
FormTokenResponse bean = new FormTokenResponse();
bean.setResponseType(OAuthConstants.TOKEN_RESPONSE_TYPE);
bean.setRedirectUri(state.getRedirectUri());
bean.setState(state.getState());
bean.setAccessToken(clientToken.getTokenKey());
bean.setAccessTokenType(clientToken.getTokenType());
bean.setAccessTokenExpiresIn(clientToken.getExpiresIn());
bean.getParameters().putAll(clientToken.getParameters());
return bean;
}
Aggregations