Search in sources :

Example 16 with Userinfo

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

Example 17 with Userinfo

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

Example 18 with Userinfo

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());
}
Also used : Oauth2(com.google.api.services.oauth2.Oauth2) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential)

Example 19 with Userinfo

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

Example 20 with Userinfo

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

Aggregations

Userinfo (com.google.api.services.oauth2.model.Userinfo)10 Oauth2 (com.google.api.services.oauth2.Oauth2)8 Userinfoplus (com.google.api.services.oauth2.model.Userinfoplus)6 IOException (java.io.IOException)5 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)4 UserInfo (com.developmentontheedge.be5.model.UserInfo)3 Credential (com.google.api.client.auth.oauth2.Credential)3 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)3 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)3 UserInfo (org.alfresco.repo.event.v1.model.UserInfo)3 JsonObject (com.google.gson.JsonObject)2 CustomWebApplicationException (io.dockstore.webservice.CustomWebApplicationException)2 Test (org.junit.jupiter.api.Test)2 FirecloudMe (org.pmiops.workbench.firecloud.model.FirecloudMe)2 FirecloudUserInfo (org.pmiops.workbench.firecloud.model.FirecloudUserInfo)2 Timed (com.codahale.metrics.annotation.Timed)1 Session (com.developmentontheedge.be5.api.Session)1 JsonView (com.fasterxml.jackson.annotation.JsonView)1 ForIntent (com.google.actions.api.ForIntent)1 TransactionDecision (com.google.actions.api.response.helperintent.transactions.v3.TransactionDecision)1