use of com.google.api.services.actions_fulfillment.v2.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.actions_fulfillment.v2.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.actions_fulfillment.v2.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.actions_fulfillment.v2.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;
}
use of com.google.api.services.actions_fulfillment.v2.model.UserInfo in project gatein-portal by Meeds-io.
the class GoogleProcessorImpl method obtainUserInfo.
@Override
public Userinfo obtainUserInfo(GoogleAccessTokenContext accessTokenContext) {
final Oauth2 oauth2 = getOAuth2Instance(accessTokenContext);
GoogleRequest<Userinfo> googleRequest = new GoogleRequest<Userinfo>() {
@Override
protected Userinfo invokeRequest(GoogleAccessTokenContext accessTokenContext) throws IOException {
return oauth2.userinfo().v2().me().get().execute();
}
@Override
protected OAuthException createException(IOException cause) {
if (cause instanceof HttpResponseException) {
return new OAuthException(OAuthExceptionCode.ACCESS_TOKEN_ERROR, "Error when obtaining userInfo: " + cause.getMessage(), cause);
} else {
return new OAuthException(OAuthExceptionCode.IO_ERROR, "IO Error when obtaining userInfo: " + cause.getMessage(), cause);
}
}
};
Userinfo uinfo = googleRequest.executeRequest(accessTokenContext, this);
if (log.isTraceEnabled()) {
log.trace("Successfully obtained userInfo from google: " + uinfo);
}
return uinfo;
}
Aggregations