Search in sources :

Example 11 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project engine by Lumeer.

the class Auth0Filter method getUserInfo.

private User getUserInfo(final String accessToken) throws Auth0Exception {
    final AuthAPI auth0 = new AuthAPI(domain, clientId, clientSecret);
    final Request<UserInfo> info = auth0.userInfo(accessToken);
    final Map<String, Object> values = info.execute().getValues();
    final String nickname = (String) values.get("nickname");
    final String sub = (String) values.get("sub");
    final String name = (String) values.get("name");
    final String email = (String) values.get("email");
    final Boolean emailVerified = (Boolean) values.get("email_verified");
    final User user = new User(email == null ? (sub.startsWith("google-oauth2") ? nickname + "@gmail.com" : name) : email);
    user.setAuthIds(new HashSet<>(Arrays.asList(sub)));
    user.setName(name);
    user.setEmailVerified(emailVerified != null && emailVerified);
    return user;
}
Also used : User(io.lumeer.api.model.User) UserInfo(com.auth0.json.auth.UserInfo) AuthAPI(com.auth0.client.auth.AuthAPI)

Example 12 with AuthAPI

use of com.auth0.client.auth.AuthAPI in project engine by Lumeer.

the class UserAuth0Utils method requestManagementApiToken.

private String requestManagementApiToken() throws Auth0Exception {
    final AuthAPI auth0 = new AuthAPI(domain, backendClientId, backendClientSecret);
    AuthRequest req = auth0.requestToken("https://" + domain + "/api/v2/");
    return req.execute().getAccessToken();
}
Also used : AuthRequest(com.auth0.net.AuthRequest) AuthAPI(com.auth0.client.auth.AuthAPI)

Example 13 with AuthAPI

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

the class AuthAPITest method shouldUseConfiguredMaxRequestsPerHost.

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

Example 14 with AuthAPI

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

the class AuthAPITest method proxyShouldNotProcessAlreadyAuthenticatedRequest.

@Test
public void proxyShouldNotProcessAlreadyAuthenticatedRequest() throws Exception {
    Proxy proxy = Mockito.mock(Proxy.class);
    ProxyOptions proxyOptions = new ProxyOptions(proxy);
    proxyOptions.setBasicAuthentication("johndoe", "psswd".toCharArray());
    assertThat(proxyOptions.getBasicAuthentication(), is("Basic am9obmRvZTpwc3N3ZA=="));
    HttpOptions httpOptions = new HttpOptions();
    httpOptions.setProxyOptions(proxyOptions);
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, httpOptions);
    assertThat(api.getClient().proxy(), is(proxy));
    Authenticator authenticator = api.getClient().proxyAuthenticator();
    assertThat(authenticator, is(notNullValue()));
    Route route = Mockito.mock(Route.class);
    okhttp3.Request alreadyAuthenticatedRequest = new okhttp3.Request.Builder().url("https://test.com/app").addHeader("some-header", "some-value").header("Proxy-Authorization", "pre-existing-value").build();
    okhttp3.Response alreadyAuthenticatedResponse = new okhttp3.Response.Builder().protocol(Protocol.HTTP_2).code(200).message("OK").request(alreadyAuthenticatedRequest).build();
    okhttp3.Request processedRequest = authenticator.authenticate(route, alreadyAuthenticatedResponse);
    assertThat(processedRequest, is(nullValue()));
}
Also used : Proxy(java.net.Proxy) ProxyOptions(com.auth0.client.ProxyOptions) okhttp3(okhttp3) HttpOptions(com.auth0.client.HttpOptions) Test(org.junit.Test)

Example 15 with AuthAPI

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

the class AuthAPITest method shouldUseProxyWithAuthentication.

@Test
public void shouldUseProxyWithAuthentication() throws Exception {
    Proxy proxy = Mockito.mock(Proxy.class);
    ProxyOptions proxyOptions = new ProxyOptions(proxy);
    proxyOptions.setBasicAuthentication("johndoe", "psswd".toCharArray());
    assertThat(proxyOptions.getBasicAuthentication(), is("Basic am9obmRvZTpwc3N3ZA=="));
    HttpOptions httpOptions = new HttpOptions();
    httpOptions.setProxyOptions(proxyOptions);
    AuthAPI api = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET, httpOptions);
    assertThat(api.getClient().proxy(), is(proxy));
    Authenticator authenticator = api.getClient().proxyAuthenticator();
    assertThat(authenticator, is(notNullValue()));
    Route route = Mockito.mock(Route.class);
    okhttp3.Request nonAuthenticatedRequest = new okhttp3.Request.Builder().url("https://test.com/app").addHeader("some-header", "some-value").build();
    okhttp3.Response nonAuthenticatedResponse = new okhttp3.Response.Builder().protocol(Protocol.HTTP_2).code(200).message("OK").request(nonAuthenticatedRequest).build();
    okhttp3.Request processedRequest = authenticator.authenticate(route, nonAuthenticatedResponse);
    assertThat(processedRequest, is(notNullValue()));
    assertThat(processedRequest.url(), is(HttpUrl.parse("https://test.com/app")));
    assertThat(processedRequest.header("Proxy-Authorization"), is(proxyOptions.getBasicAuthentication()));
    assertThat(processedRequest.header("some-header"), is("some-value"));
}
Also used : ProxyOptions(com.auth0.client.ProxyOptions) HttpOptions(com.auth0.client.HttpOptions) Request(com.auth0.net.Request) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Proxy(java.net.Proxy) okhttp3(okhttp3) Test(org.junit.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