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();
}
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();
}
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);
}
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();
}
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);
}
Aggregations