Search in sources :

Example 1 with ImplicitAccessTokenProvider

use of org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider in project spring-security-oauth by spring-projects.

the class ImplicitProviderTests method testPostForAutomaticApprovalToken.

@Test
@OAuth2ContextConfiguration(resource = AutoApproveImplicit.class, initialize = false)
public void testPostForAutomaticApprovalToken() throws Exception {
    final ImplicitAccessTokenProvider implicitProvider = new ImplicitAccessTokenProvider();
    implicitProvider.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(new ClientHttpRequestInterceptor() {

        public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
            ClientHttpResponse result = execution.execute(request, body);
            latestHeaders = result.getHeaders();
            return result;
        }
    }));
    context.setAccessTokenProvider(implicitProvider);
    context.getAccessTokenRequest().setCookie(cookie);
    assertNotNull(context.getAccessToken());
    assertTrue("Wrong location header: " + latestHeaders.getLocation().getFragment(), latestHeaders.getLocation().getFragment().contains("scope=read write trust"));
}
Also used : HttpRequest(org.springframework.http.HttpRequest) ImplicitAccessTokenProvider(org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider) ClientHttpRequestExecution(org.springframework.http.client.ClientHttpRequestExecution) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) ClientHttpRequestInterceptor(org.springframework.http.client.ClientHttpRequestInterceptor) OAuth2ContextConfiguration(org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 HttpRequest (org.springframework.http.HttpRequest)1 ClientHttpRequestExecution (org.springframework.http.client.ClientHttpRequestExecution)1 ClientHttpRequestInterceptor (org.springframework.http.client.ClientHttpRequestInterceptor)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1 OAuth2ContextConfiguration (org.springframework.security.oauth2.client.test.OAuth2ContextConfiguration)1 ImplicitAccessTokenProvider (org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider)1