Search in sources :

Example 11 with UserInfo

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);
}
Also used : Userinfo(com.google.api.services.oauth2.model.Userinfo)

Example 12 with UserInfo

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));
}
Also used : Userinfo(com.google.api.services.oauth2.model.Userinfo) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 13 with UserInfo

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;
}
Also used : Oauth2(com.google.api.services.oauth2.Oauth2) Userinfo(com.google.api.services.oauth2.model.Userinfo)

Example 14 with UserInfo

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;
}
Also used : Userinfo(com.google.api.services.oauth2.model.Userinfo) GoogleAccessTokenContext(org.gatein.security.oauth.google.GoogleAccessTokenContext) GoogleProcessor(org.gatein.security.oauth.google.GoogleProcessor)

Example 15 with UserInfo

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;
}
Also used : Oauth2(com.google.api.services.oauth2.Oauth2) OAuthException(org.gatein.security.oauth.exception.OAuthException) Userinfo(com.google.api.services.oauth2.model.Userinfo) HttpResponseException(com.google.api.client.http.HttpResponseException) IOException(java.io.IOException)

Aggregations

Userinfo (com.google.api.services.oauth2.model.Userinfo)10 UserInfo (com.developmentontheedge.be5.model.UserInfo)3 Oauth2 (com.google.api.services.oauth2.Oauth2)3 UserInfo (org.alfresco.repo.event.v1.model.UserInfo)3 ApiException (com.haleconnect.api.user.v1.ApiException)2 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 FirecloudMe (org.pmiops.workbench.firecloud.model.FirecloudMe)2 FirecloudUserInfo (org.pmiops.workbench.firecloud.model.FirecloudUserInfo)2 Session (com.developmentontheedge.be5.api.Session)1 ForIntent (com.google.actions.api.ForIntent)1 TransactionDecision (com.google.actions.api.response.helperintent.transactions.v3.TransactionDecision)1 Credential (com.google.api.client.auth.oauth2.Credential)1 HttpResponseException (com.google.api.client.http.HttpResponseException)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 Action (com.google.api.services.actions_fulfillment.v2.model.Action)1 GooglePaymentOption (com.google.api.services.actions_fulfillment.v2.model.GooglePaymentOption)1 LineItemV3 (com.google.api.services.actions_fulfillment.v2.model.LineItemV3)1 Location (com.google.api.services.actions_fulfillment.v2.model.Location)1