use of com.google.api.services.oauth2.model.Userinfo in project workbench by all-of-us.
the class AuthInterceptorTest method mockUserInfoSuccess.
private void mockUserInfoSuccess() {
Userinfo userInfo = new Userinfo();
userInfo.setEmail("bob@fake-domain.org");
when(userInfoService.getUserInfo("foo")).thenReturn(userInfo);
when(userDao.findUserByUsername("bob@fake-domain.org")).thenReturn(user);
}
use of com.google.api.services.oauth2.model.Userinfo in project workbench by all-of-us.
the class AuthInterceptorTest method preHandleGet_firecloudLookupFails.
@Test
public void preHandleGet_firecloudLookupFails() throws Exception {
mockGetCallWithBearerToken();
Userinfo userInfo = new Userinfo();
userInfo.setEmail("bob@bad-domain.org");
when(userInfoService.getUserInfo("foo")).thenReturn(userInfo);
when(fireCloudService.getMe()).thenThrow(new NotFoundException());
assertThrows(NotFoundException.class, () -> interceptor.preHandle(mockRequest, mockResponse, mockHandler));
}
use of com.google.api.services.oauth2.model.Userinfo in project workbench by all-of-us.
the class UserInfoService method getUserInfo.
public Userinfo getUserInfo(String token) {
GoogleCredential credential = new GoogleCredential().setAccessToken(token);
Oauth2 oauth2 = new Oauth2.Builder(httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build();
return retryHandler.run((context) -> oauth2.userinfo().get().execute());
}
use of com.google.api.services.oauth2.model.Userinfo in project java-docs-samples by GoogleCloudPlatform.
the class Utils method getUserInfo.
// [START gae_java11_oauth2_get_user]
/**
* Obtain end-user authorization grant for Google APIs and return username
*/
public static String getUserInfo(Credential credential) throws IOException {
Oauth2 oauth2Client = new Oauth2.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APP_NAME).build();
// Retrieve user profile
Userinfo userInfo = oauth2Client.userinfo().get().execute();
String username = userInfo.getGivenName();
return username;
}
use of com.google.api.services.oauth2.model.Userinfo in project gatein-portal by Meeds-io.
the class GoogleFilter method getOAuthPrincipal.
@Override
protected OAuthPrincipal<GoogleAccessTokenContext> getOAuthPrincipal(HttpServletRequest request, HttpServletResponse response, InteractionState<GoogleAccessTokenContext> interactionState) {
GoogleAccessTokenContext accessTokenContext = interactionState.getAccessTokenContext();
Userinfo userInfo = ((GoogleProcessor) getOauthProviderProcessor()).obtainUserInfo(accessTokenContext);
if (log.isTraceEnabled()) {
log.trace("Obtained tokenResponse from Google authentication: " + accessTokenContext);
log.trace("User info from Google: " + userInfo);
}
OAuthPrincipal<GoogleAccessTokenContext> oauthPrincipal = OAuthUtils.convertGoogleInfoToOAuthPrincipal(userInfo, accessTokenContext, getOAuthProvider());
return oauthPrincipal;
}
Aggregations