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());
}
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));
}
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());
}
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));
}
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);
}
Aggregations