use of org.apache.cxf.rs.security.oauth2.common.Client in project cxf by apache.
the class OIDCFiltersTest method makeAuthorizationCodeInvocation.
private String makeAuthorizationCodeInvocation(WebClient client) {
// Make initial authorization request
client.type("application/json").accept("application/json");
Response response = client.get();
OAuthAuthorizationData authzData = response.readEntity(OAuthAuthorizationData.class);
// Now call "decision" to get the authorization code grant
client.path("decision");
client.type("application/x-www-form-urlencoded");
Form form = new Form();
form.param("session_authenticity_token", authzData.getAuthenticityToken());
form.param("client_id", authzData.getClientId());
form.param("redirect_uri", authzData.getRedirectUri());
if (authzData.getProposedScope() != null) {
form.param("scope", authzData.getProposedScope());
}
form.param("state", authzData.getState());
form.param("oauthDecision", "allow");
response = client.post(form);
return response.getHeaderString("Location");
}
use of org.apache.cxf.rs.security.oauth2.common.Client in project tesb-rt-se by Talend.
the class ThirdPartyRegistrationService method register.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/")
public ConsumerRegistration register(MultipartBody body) {
String appName = body.getAttachmentObject("appName", String.class);
String appURI = body.getAttachmentObject("appURI", String.class);
String appRedirectURI = body.getAttachmentObject("appRedirectURI", String.class);
String appDesc = body.getAttachmentObject("appDescription", String.class);
URI logoURI = null;
Attachment att = body.getAttachment("appLogo");
if (att != null) {
InputStream logoStream = att.getObject(InputStream.class);
CachedOutputStream cos = new CachedOutputStream();
try {
IOUtils.copy(logoStream, cos);
appLogos.put(appName.toLowerCase(), cos);
UriBuilder ub = uriInfo.getAbsolutePathBuilder();
ub.path("logo").path(appName.toLowerCase());
ContentDisposition cd = att.getContentDisposition();
if (cd != null && cd.getParameter("filename") != null) {
ub.path(cd.getParameter("filename"));
}
logoURI = ub.build();
} catch (IOException ex) {
// ignore
}
}
String clientId = generateClientId(appName, appURI);
String clientSecret = generateClientSecret();
Client newClient = new Client(clientId, clientSecret, true, appName, appURI);
newClient.setApplicationDescription(appDesc);
newClient.setApplicationLogoUri(logoURI.toString());
newClient.setRedirectUris(Collections.singletonList(appRedirectURI));
manager.registerClient(newClient);
return new ConsumerRegistration(clientId, clientSecret);
}
use of org.apache.cxf.rs.security.oauth2.common.Client in project teiid by teiid.
the class OAuth20CredentialImpl method getAccessToken.
protected ClientAccessToken getAccessToken() {
if (getAccessTokenString() != null) {
// if we have access_token directly, use it
return new ClientAccessToken(OAuthConstants.ACCESS_TOKEN_TYPE, getAccessTokenString());
}
Consumer consumer = new Consumer(getClientId(), getClientSecret());
WebClient client = WebClient.create(getAccessTokenURI());
RefreshTokenGrant grant = new RefreshTokenGrant(getRefreshToken());
return OAuthClientUtils.getAccessToken(client, consumer, grant, null, "Bearer", false);
}
use of org.apache.cxf.rs.security.oauth2.common.Client in project testcases by coheigea.
the class AuthorizationGrantTest method testAuthorizationCodeGrant.
@org.junit.Test
public void testAuthorizationCodeGrant() throws Exception {
URL busFile = AuthorizationGrantTest.class.getResource("cxf-client.xml");
String address = "https://localhost:" + PORT + "/services/";
WebClient client = WebClient.create(address, setupProviders(), "alice", "security", busFile.toString());
// Save the Cookie for the second request...
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
// Get Authorization Code
String code = getAuthorizationCode(client);
assertNotNull(code);
// Now get the access token
client = WebClient.create(address, setupProviders(), "consumer-id", "this-is-a-secret", busFile.toString());
// Save the Cookie for the second request...
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
ClientAccessToken accessToken = getAccessTokenWithAuthorizationCode(client, code);
assertNotNull(accessToken.getTokenKey());
}
use of org.apache.cxf.rs.security.oauth2.common.Client in project testcases by coheigea.
the class AuthorizationGrantTest method testClientCredentialsGrant.
@org.junit.Test
public void testClientCredentialsGrant() throws Exception {
URL busFile = AuthorizationGrantTest.class.getResource("cxf-client.xml");
String address = "https://localhost:" + PORT + "/services/";
WebClient client = WebClient.create(address, setupProviders(), "consumer-id", "this-is-a-secret", busFile.toString());
// Get Access Token
client.type("application/x-www-form-urlencoded").accept("application/json");
client.path("token");
Form form = new Form();
form.param("grant_type", "client_credentials");
Response response = client.post(form);
ClientAccessToken accessToken = response.readEntity(ClientAccessToken.class);
assertNotNull(accessToken.getTokenKey());
assertNotNull(accessToken.getRefreshToken());
}
Aggregations