Search in sources :

Example 1 with UserInfo

use of com.google.api.services.actions_fulfillment.v2.model.UserInfo in project ezyfox-examples by tvd12.

the class LoginController method loginWithGoogle.

@DoGet("/google-login-callback")
public Object loginWithGoogle(@RequestParam String code) {
    String googleAccessToken = googleService.getAccessToken(code);
    if (googleAccessToken == null) {
        return Redirect.to("/login-error");
    }
    Userinfo googleUserInfo = googleService.getUserInfoByAccessToken(googleAccessToken);
    if (googleUserInfo == null) {
        return Redirect.to("/login-error");
    }
    boolean userExisted = true;
    User user = userService.getUserInfoByEmail(googleUserInfo.getEmail());
    if (user == null) {
        userExisted = false;
        user = userService.saveGoogleUserInfo(googleUserInfo);
        userDataService.saveGoogleToken(user.getId(), googleAccessToken);
    }
    String accessToken = authenticationService.generateAccessToken(user.getId());
    return userExisted && user.getStatus() == UserStatus.UPDATED ? Redirect.builder().uri("/home").addCookie("accessToken", accessToken).build() : Redirect.builder().uri("/user/update").addCookie("accessToken", accessToken).build();
}
Also used : User(org.youngmonkeys.example.ezyhttp.login.entity.User) Userinfo(com.google.api.services.oauth2.model.Userinfo)

Example 2 with UserInfo

use of com.google.api.services.actions_fulfillment.v2.model.UserInfo in project hale by halestudio.

the class HaleConnectServiceImpl method login.

/**
 * @see eu.esdihumboldt.hale.io.haleconnect.HaleConnectService#login(java.lang.String,
 *      java.lang.String)
 */
@Override
public boolean login(String username, String password) throws HaleConnectException {
    LoginApi loginApi = UserServiceHelper.getLoginApi(this);
    Credentials credentials = UserServiceHelper.buildCredentials(username, password);
    try {
        Token token = loginApi.login(credentials);
        if (token != null) {
            UsersApi usersApi = UserServiceHelper.getUsersApi(this, token.getToken());
            // First get the current user's profile to obtain the user ID
            // required to fetch the extended profile (including the user's
            // roles/organisations) in the next step
            UserInfo shortProfile = usersApi.getProfileOfCurrentUser();
            session = new HaleConnectSessionImpl(username, token.getToken(), usersApi.getProfile(shortProfile.getId()));
            notifyLoginStateChanged();
        } else {
            clearSession();
        }
    } catch (ApiException e) {
        if (e.getCode() == 401) {
            clearSession();
        } else {
            throw new HaleConnectException(e.getMessage(), e);
        }
    }
    return isLoggedIn();
}
Also used : UsersApi(com.haleconnect.api.user.v1.api.UsersApi) Token(com.haleconnect.api.user.v1.model.Token) UserInfo(com.haleconnect.api.user.v1.model.UserInfo) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) LoginApi(com.haleconnect.api.user.v1.api.LoginApi) Credentials(com.haleconnect.api.user.v1.model.Credentials) ApiException(com.haleconnect.api.user.v1.ApiException)

Example 3 with UserInfo

use of com.google.api.services.actions_fulfillment.v2.model.UserInfo in project be5 by DevelopmentOnTheEdge.

the class AuthenticationPropagationListener method requestInitialized.

@Override
public void requestInitialized(ServletRequestEvent event) {
    HttpServletRequest request = (HttpServletRequest) event.getServletRequest();
    HttpSession session = request.getSession(false);
    if (session == null) {
        return;
    }
    UserInfo user = (UserInfo) session.getAttribute(SessionConstants.USER_INFO);
    UserInfoHolder.setUserInfo(user);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) UserInfo(com.developmentontheedge.be5.model.UserInfo)

Example 4 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_firecloudLookupSucceeds.

@Test
public void preHandleGet_firecloudLookupSucceeds() throws Exception {
    mockGetCallWithBearerToken();
    Userinfo userInfo = new Userinfo();
    userInfo.setEmail("bob@bad-domain.org");
    when(userInfoService.getUserInfo("foo")).thenReturn(userInfo);
    FirecloudUserInfo fcUserInfo = new FirecloudUserInfo();
    fcUserInfo.setUserEmail("bob@fake-domain.org");
    FirecloudMe me = new FirecloudMe();
    me.setUserInfo(fcUserInfo);
    when(fireCloudService.getMe()).thenReturn(me);
    when(userDao.findUserByUsername("bob@fake-domain.org")).thenReturn(user);
    assertThat(interceptor.preHandle(mockRequest, mockResponse, mockHandler)).isTrue();
}
Also used : Userinfo(com.google.api.services.oauth2.model.Userinfo) FirecloudMe(org.pmiops.workbench.firecloud.model.FirecloudMe) FirecloudUserInfo(org.pmiops.workbench.firecloud.model.FirecloudUserInfo) Test(org.junit.jupiter.api.Test)

Example 5 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_firecloudLookupSucceedsNoUserRecordWrongDomain.

@Test
public void preHandleGet_firecloudLookupSucceedsNoUserRecordWrongDomain() throws Exception {
    mockGetCallWithBearerToken();
    Userinfo userInfo = new Userinfo();
    userInfo.setEmail("bob@bad-domain.org");
    when(userInfoService.getUserInfo("foo")).thenReturn(userInfo);
    FirecloudUserInfo fcUserInfo = new FirecloudUserInfo();
    fcUserInfo.setUserEmail("bob@also-bad-domain.org");
    FirecloudMe me = new FirecloudMe();
    me.setUserInfo(fcUserInfo);
    when(fireCloudService.getMe()).thenReturn(me);
    when(userDao.findUserByUsername("bob@also-bad-domain.org")).thenReturn(null);
    assertThat(interceptor.preHandle(mockRequest, mockResponse, mockHandler)).isFalse();
    verify(mockResponse).sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
Also used : Userinfo(com.google.api.services.oauth2.model.Userinfo) FirecloudMe(org.pmiops.workbench.firecloud.model.FirecloudMe) FirecloudUserInfo(org.pmiops.workbench.firecloud.model.FirecloudUserInfo) Test(org.junit.jupiter.api.Test)

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