Search in sources :

Example 21 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project auth0-java by auth0.

the class AuthAPITest method shouldConfigureHeaderLoggingFromOptions.

@Test
public void shouldConfigureHeaderLoggingFromOptions() {
    LoggingOptions loggingOptions = new LoggingOptions(LoggingOptions.LogLevel.HEADERS);
    Set<String> headersToRedact = new HashSet<>();
    headersToRedact.add("Authorization");
    headersToRedact.add("Cookie");
    loggingOptions.setHeadersToRedact(headersToRedact);
    HttpOptions options = new HttpOptions();
    options.setLoggingOptions(loggingOptions);
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, options);
    assertThat(api.getClient().interceptors(), hasItem(isA(HttpLoggingInterceptor.class)));
    for (Interceptor i : api.getClient().interceptors()) {
        if (i instanceof HttpLoggingInterceptor) {
            HttpLoggingInterceptor logging = (HttpLoggingInterceptor) i;
            assertThat(logging.getLevel(), is(Level.HEADERS));
        }
    }
}
Also used : HttpOptions(com.auth0.client.HttpOptions) LoggingOptions(com.auth0.client.LoggingOptions) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Test(org.junit.Test)

Example 22 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project auth0-java-mvc-common by auth0.

the class AuthorizeUrlTest method setUp.

@BeforeEach
public void setUp() {
    client = new AuthAPI("domain.auth0.com", "clientId", "clientSecret");
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AuthAPI(com.auth0.client.auth.AuthAPI) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project auth0-java-mvc-common by auth0.

the class RequestProcessorTest method shouldBuildAuthorizeUrlWithFormPostIfResponseTypeIsToken.

@Test
public void shouldBuildAuthorizeUrlWithFormPostIfResponseTypeIsToken() {
    AuthAPI client = new AuthAPI("me.auth0.com", "clientId", "clientSecret");
    RequestProcessor handler = new RequestProcessor.Builder(client, "token", verifyOptions).build();
    HttpServletRequest request = new MockHttpServletRequest();
    AuthorizeUrl builder = handler.buildAuthorizeUrl(request, response, "https://redirect.uri/here", "state", "nonce");
    String authorizeUrl = builder.build();
    assertThat(authorizeUrl, is(notNullValue()));
    assertThat(authorizeUrl, CoreMatchers.startsWith("https://me.auth0.com/authorize?"));
    assertThat(authorizeUrl, containsString("client_id=clientId"));
    assertThat(authorizeUrl, containsString("redirect_uri=https://redirect.uri/here"));
    assertThat(authorizeUrl, containsString("response_type=token"));
    assertThat(authorizeUrl, containsString("scope=openid"));
    assertThat(authorizeUrl, containsString("state=state"));
    assertThat(authorizeUrl, containsString("response_mode=form_post"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AuthAPI(com.auth0.client.auth.AuthAPI) Test(org.junit.jupiter.api.Test)

Example 24 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project auth0-java-mvc-common by auth0.

the class RequestProcessorTest method shouldNotSetNullNonceIfRequestTypeIsIdToken.

@Test
public void shouldNotSetNullNonceIfRequestTypeIsIdToken() {
    AuthAPI client = new AuthAPI("me.auth0.com", "clientId", "clientSecret");
    RequestProcessor handler = new RequestProcessor.Builder(client, "id_token", verifyOptions).build();
    HttpServletRequest request = new MockHttpServletRequest();
    AuthorizeUrl builder = handler.buildAuthorizeUrl(request, response, "https://redirect.uri/here", "state", null);
    String authorizeUrl = builder.build();
    assertThat(authorizeUrl, is(notNullValue()));
    assertThat(authorizeUrl, not(containsString("nonce=nonce")));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) AuthAPI(com.auth0.client.auth.AuthAPI) Test(org.junit.jupiter.api.Test)

Aggregations

AuthAPI (com.auth0.client.auth.AuthAPI)12 HttpOptions (com.auth0.client.HttpOptions)11 Test (org.junit.Test)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 Test (org.junit.jupiter.api.Test)7 LoggingOptions (com.auth0.client.LoggingOptions)4 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)4 ProxyOptions (com.auth0.client.ProxyOptions)3 Proxy (java.net.Proxy)3 okhttp3 (okhttp3)3 UserInfo (com.auth0.json.auth.UserInfo)2 AuthRequest (com.auth0.net.AuthRequest)2 Request (com.auth0.net.Request)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Before (org.junit.Before)2 MockServer (com.auth0.client.MockServer)1 APIException (com.auth0.exception.APIException)1 Auth0Exception (com.auth0.exception.Auth0Exception)1 TokenHolder (com.auth0.json.auth.TokenHolder)1