Search in sources :

Example 1 with AuthAPI

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

the class AuthAPITest method shouldConfigureBodyLoggingFromOptions.

@Test
public void shouldConfigureBodyLoggingFromOptions() {
    LoggingOptions loggingOptions = new LoggingOptions(LoggingOptions.LogLevel.BODY);
    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.BODY));
        }
    }
}
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 2 with AuthAPI

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

the class AuthAPITest method shouldUseConfiguredMaxRequests.

@Test
public void shouldUseConfiguredMaxRequests() {
    HttpOptions options = new HttpOptions();
    options.setMaxRequests(10);
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, options);
    assertThat(api.getClient().dispatcher().getMaxRequests(), is(10));
}
Also used : HttpOptions(com.auth0.client.HttpOptions) Test(org.junit.Test)

Example 3 with AuthAPI

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

the class AuthAPITest method shouldUseConfiguredTimeoutValues.

@Test
public void shouldUseConfiguredTimeoutValues() {
    HttpOptions options = new HttpOptions();
    options.setConnectTimeout(20);
    options.setReadTimeout(30);
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, options);
    assertThat(api.getClient().connectTimeoutMillis(), is(20 * 1000));
    assertThat(api.getClient().readTimeoutMillis(), is(30 * 1000));
}
Also used : HttpOptions(com.auth0.client.HttpOptions) Test(org.junit.Test)

Example 4 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project app-auth0-idprovider by enonic.

the class Auth0CallbackService method retrieveUserInfo.

private UserInfo retrieveUserInfo(IdProviderKey idProviderKey, Tokens tokens) throws Auth0Exception {
    final String appClientId = configurationService.getAppClientId(idProviderKey);
    final String appSecret = configurationService.getAppSecret(idProviderKey);
    final String appDomain = configurationService.getAppDomain(idProviderKey);
    final UserInfo userInfo = new AuthAPI(appDomain, appClientId, appSecret).userInfo(tokens.getAccessToken()).execute();
    return userInfo;
}
Also used : UserInfo(com.auth0.json.auth.UserInfo) AuthAPI(com.auth0.client.auth.AuthAPI)

Example 5 with AuthAPI

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

the class RequestProcessorTest method shouldSetMaxAgeIfProvided.

@Test
public void shouldSetMaxAgeIfProvided() {
    AuthAPI client = new AuthAPI("me.auth0.com", "clientId", "clientSecret");
    when(verifyOptions.getMaxAge()).thenReturn(906030);
    RequestProcessor handler = new RequestProcessor.Builder(client, "code", 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, containsString("max_age=906030"));
}
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