Search in sources :

Example 1 with ClientCredentialsGrant

use of org.apache.cxf.rs.security.oauth2.grants.clientcred.ClientCredentialsGrant in project cxf by apache.

the class JAXRSOAuth2Test method testBasicAuthClientCred.

@Test
public void testBasicAuthClientCred() throws Exception {
    String address = "https://localhost:" + PORT + "/oauth2/token";
    WebClient wc = createWebClient(address);
    ClientCredentialsGrant grant = new ClientCredentialsGrant();
    // Pass client_id & client_secret as form properties
    // (instead WebClient can be initialized with username & password)
    grant.setClientId("bob");
    grant.setClientSecret("bobPassword");
    try {
        OAuthClientUtils.getAccessToken(wc, grant);
        fail("Form based authentication is not supported");
    } catch (OAuthServiceException ex) {
        assertEquals(OAuthConstants.UNAUTHORIZED_CLIENT, ex.getError().getError());
    }
    ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer("bob", "bobPassword"), new ClientCredentialsGrant(), true);
    assertNotNull(at.getTokenKey());
}
Also used : Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException) ClientCredentialsGrant(org.apache.cxf.rs.security.oauth2.grants.clientcred.ClientCredentialsGrant) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

WebClient (org.apache.cxf.jaxrs.client.WebClient)1 Consumer (org.apache.cxf.rs.security.oauth2.client.Consumer)1 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)1 ClientCredentialsGrant (org.apache.cxf.rs.security.oauth2.grants.clientcred.ClientCredentialsGrant)1 OAuthServiceException (org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException)1 Test (org.junit.Test)1