Search in sources :

Example 11 with User

use of com.google.api.server.spi.auth.common.User in project endpoints-java by cloudendpoints.

the class GoogleJwtAuthenticatorTest method testAuthenticate_appEngineUser.

@Test
public void testAuthenticate_appEngineUser() throws GeneralSecurityException, IOException {
    attr.set(Attribute.REQUIRE_APPENGINE_USER, true);
    when(verifier.verify(TOKEN)).thenReturn(token);
    when(config.getClientIds()).thenReturn(ImmutableList.of(CLIENT_ID));
    when(config.getAudiences()).thenReturn(ImmutableList.of(AUDIENCE));
    User user = authenticator.authenticate(request);
    assertEquals(EMAIL, user.getEmail());
    assertEquals(USER_ID, user.getId());
    com.google.appengine.api.users.User appEngineuser = attr.get(Attribute.AUTHENTICATED_APPENGINE_USER);
    assertEquals(EMAIL, appEngineuser.getEmail());
    assertNull(appEngineuser.getUserId());
}
Also used : User(com.google.api.server.spi.auth.common.User) Test(org.junit.Test)

Example 12 with User

use of com.google.api.server.spi.auth.common.User in project endpoints-java by cloudendpoints.

the class GoogleJwtAuthenticatorTest method testAuthenticate_skipClientIdCheck.

@Test
public void testAuthenticate_skipClientIdCheck() throws Exception {
    request.removeAttribute(Attribute.ENABLE_CLIENT_ID_WHITELIST);
    when(verifier.verify(TOKEN)).thenReturn(token);
    when(config.getClientIds()).thenReturn(ImmutableList.of("clientId2"));
    when(config.getAudiences()).thenReturn(ImmutableList.of(AUDIENCE));
    User user = authenticator.authenticate(request);
    assertEquals(EMAIL, user.getEmail());
    assertEquals(USER_ID, user.getId());
    assertNotNull(attr.get(Attribute.ID_TOKEN));
}
Also used : User(com.google.api.server.spi.auth.common.User) Test(org.junit.Test)

Example 13 with User

use of com.google.api.server.spi.auth.common.User in project endpoints-java by cloudendpoints.

the class GoogleOAuth2AuthenticatorTest method testAuthenticate_appEngineUser.

@Test
public void testAuthenticate_appEngineUser() throws ServiceUnavailableException {
    attr.set(Attribute.REQUIRE_APPENGINE_USER, true);
    when(config.getScopeExpression()).thenReturn(AuthScopeExpressions.interpret("scope1"));
    when(config.getClientIds()).thenReturn(ImmutableList.of(CLIENT_ID));
    User user = authenticator.authenticate(request);
    assertEquals(EMAIL, user.getEmail());
    assertEquals(USER_ID, user.getId());
    com.google.appengine.api.users.User appEngineuser = (com.google.appengine.api.users.User) attr.get(Attribute.AUTHENTICATED_APPENGINE_USER);
    assertEquals(EMAIL, appEngineuser.getEmail());
    assertNull(appEngineuser.getUserId());
}
Also used : User(com.google.api.server.spi.auth.common.User) Test(org.junit.Test)

Example 14 with User

use of com.google.api.server.spi.auth.common.User in project endpoints-java by cloudendpoints.

the class GoogleOAuth2AuthenticatorTest method testAuthenticate_skipClientIdCheck.

@Test
public void testAuthenticate_skipClientIdCheck() throws ServiceUnavailableException {
    request.removeAttribute(Attribute.ENABLE_CLIENT_ID_WHITELIST);
    when(config.getScopeExpression()).thenReturn(AuthScopeExpressions.interpret("scope1"));
    when(config.getClientIds()).thenReturn(ImmutableList.of("clientId2"));
    User user = authenticator.authenticate(request);
    assertEquals(EMAIL, user.getEmail());
    assertEquals(USER_ID, user.getId());
    assertNotNull(attr.get(Attribute.TOKEN_INFO));
}
Also used : User(com.google.api.server.spi.auth.common.User) Test(org.junit.Test)

Example 15 with User

use of com.google.api.server.spi.auth.common.User in project endpoints-java by cloudendpoints.

the class GoogleOAuth2AuthenticatorTest method testAuthenticate.

@Test
public void testAuthenticate() throws ServiceUnavailableException {
    when(config.getScopeExpression()).thenReturn(AuthScopeExpressions.interpret("scope1"));
    when(config.getClientIds()).thenReturn(ImmutableList.of(CLIENT_ID));
    User user = authenticator.authenticate(request);
    assertEquals(EMAIL, user.getEmail());
    assertEquals(USER_ID, user.getId());
    final TokenInfo tokenInfo = attr.get(Attribute.TOKEN_INFO);
    assertNotNull(tokenInfo);
    assertEquals(EMAIL, tokenInfo.email);
    assertEquals(USER_ID, tokenInfo.userId);
}
Also used : User(com.google.api.server.spi.auth.common.User) TokenInfo(com.google.api.server.spi.auth.GoogleAuth.TokenInfo) Test(org.junit.Test)

Aggregations

User (com.google.api.server.spi.auth.common.User)15 Test (org.junit.Test)8 ApiMethodConfig (com.google.api.server.spi.config.model.ApiMethodConfig)5 Attribute (com.google.api.server.spi.request.Attribute)4 EndpointMethod (com.google.api.server.spi.EndpointMethod)3 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)3 GoogleIdToken (com.google.api.client.googleapis.auth.oauth2.GoogleIdToken)2 TokenInfo (com.google.api.server.spi.auth.GoogleAuth.TokenInfo)2 Method (java.lang.reflect.Method)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 EndpointsAuthenticator (com.google.api.server.spi.auth.EndpointsAuthenticator)1 Authenticator (com.google.api.server.spi.config.Authenticator)1 BadRequestException (com.google.api.server.spi.response.BadRequestException)1 TypeToken (com.google.common.reflect.TypeToken)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Collection (java.util.Collection)1 ServletContext (javax.servlet.ServletContext)1