List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleAuthorizationCodeRequestUrl setRedirectUri
@Override
public GoogleAuthorizationCodeRequestUrl setRedirectUri(String redirectUri)
From source file:com.abubusoft.liferay.google.GoogleOAuth.java
License:Open Source License
public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long companyId = themeDisplay.getCompanyId(); String cmd = ParamUtil.getString(request, Constants.CMD); String redirectUri = PortalUtil.getPortalURL(request) + _REDIRECT_URI; if ("login".equals(cmd)) { GoogleAuthorizationCodeFlow flow = getFlow(companyId); GoogleAuthorizationCodeRequestUrl googleAuthorizationCodeRequestUrl = flow.newAuthorizationUrl(); googleAuthorizationCodeRequestUrl.setRedirectUri(redirectUri); String url = googleAuthorizationCodeRequestUrl.build(); response.sendRedirect(url);/*from w ww. j a v a 2s. c om*/ } else if ("token".equals(cmd)) { HttpSession session = request.getSession(); String code = ParamUtil.getString(request, "code"); if (Validator.isNotNull(code)) { Credential credential = exchangeCode(companyId, code, redirectUri); Userinfoplus userinfo = getUserInfo(credential); User user = setGoogleCredentials(session, themeDisplay.getCompanyId(), userinfo); if ((user != null) && (user.getStatus() == WorkflowConstants.STATUS_INCOMPLETE)) { redirectUpdateAccount(request, response, user); return null; } PortletURL portletURL = PortletURLFactoryUtil.create(request, PortletKeys.FAST_LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE); portletURL.setWindowState(LiferayWindowState.POP_UP); portletURL.setParameter("struts_action", "/login/login_redirect"); response.sendRedirect(portletURL.toString()); } } return null; }
From source file:com.comicszone.managedbeans.social_networks.GoogleAuthorization.java
@PostConstruct @Override/*from w w w . j a v a 2s . c o m*/ public void buildUserUrl() { flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientId, clientSecret, SCOPE) .build(); final GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl(); userUrl = url.setRedirectUri(redirectUri).build(); }
From source file:com.liferay.google.GoogleOAuth.java
License:Open Source License
public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String cmd = ParamUtil.getString(request, Constants.CMD); String redirectUri = PortalUtil.getPortalURL(request) + _REDIRECT_URI; if (cmd.equals("login")) { GoogleAuthorizationCodeFlow flow = getFlow(themeDisplay.getCompanyId()); GoogleAuthorizationCodeRequestUrl googleAuthorizationCodeRequestUrl = flow.newAuthorizationUrl(); googleAuthorizationCodeRequestUrl.setRedirectUri(redirectUri); String url = googleAuthorizationCodeRequestUrl.build(); response.sendRedirect(url);/*from w w w. jav a2s . c o m*/ } else if (cmd.equals("token")) { HttpSession session = request.getSession(); String code = ParamUtil.getString(request, "code"); if (Validator.isNotNull(code)) { Credential credential = exchangeCode(themeDisplay.getCompanyId(), code, redirectUri); User user = setGoogleCredentials(session, themeDisplay.getCompanyId(), credential); if ((user != null) && (user.getStatus() == WorkflowConstants.STATUS_INCOMPLETE)) { redirectUpdateAccount(request, response, user); return null; } sendLoginRedirect(request, response); return null; } String error = ParamUtil.getString(request, "error"); if (error.equals("access_denied")) { sendLoginRedirect(request, response); return null; } } return null; }
From source file:com.liferay.google.login.hook.action.GoogleLoginAction.java
License:Open Source License
@Override public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String cmd = ParamUtil.getString(request, Constants.CMD); if (cmd.equals("login")) { GoogleAuthorizationCodeFlow googleAuthorizationCodeFlow = getGoogleAuthorizationCodeFlow( themeDisplay.getCompanyId()); GoogleAuthorizationCodeRequestUrl googleAuthorizationCodeRequestUrl = googleAuthorizationCodeFlow .newAuthorizationUrl();/*from w w w. j a va 2 s . c o m*/ googleAuthorizationCodeRequestUrl.setRedirectUri(getRedirectURI(request)); response.sendRedirect(googleAuthorizationCodeRequestUrl.build()); } else if (cmd.equals("token")) { HttpSession session = request.getSession(); String code = ParamUtil.getString(request, "code"); if (Validator.isNotNull(code)) { Credential credential = getCredential(themeDisplay.getCompanyId(), code, getRedirectURI(request)); User user = setCredential(session, themeDisplay.getCompanyId(), credential); if ((user != null) && (user.getStatus() == WorkflowConstants.STATUS_INCOMPLETE)) { sendUpdateAccountRedirect(request, response, user); return null; } sendLoginRedirect(request, response); return null; } String error = ParamUtil.getString(request, "error"); if (error.equals("access_denied")) { sendLoginRedirect(request, response); return null; } } return null; }
From source file:com.liferay.portal.security.sso.google.internal.GoogleAuthorizationImpl.java
License:Open Source License
@Override public String getLoginRedirect(long companyId, String returnRequestUri, List<String> scopes) throws Exception { GoogleAuthorizationCodeFlow googleAuthorizationCodeFlow = getGoogleAuthorizationCodeFlow(companyId, scopes); GoogleAuthorizationCodeRequestUrl googleAuthorizationCodeRequestUrl = googleAuthorizationCodeFlow .newAuthorizationUrl();/*w w w.ja v a2s . co m*/ googleAuthorizationCodeRequestUrl = googleAuthorizationCodeRequestUrl.setRedirectUri(returnRequestUri); return googleAuthorizationCodeRequestUrl.build(); }
From source file:com.mounia.tasks.GoogleAuthHelper.java
public String buildLoginUrl() { final GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl(); return url.setRedirectUri(CALLBACK_URI).setState(stateToken).build(); }
From source file:com.sarav.donormgmttool.GoogleAuthHelper.java
/** * Builds a login URL based on client ID, secret, callback URI, and scope *//*from ww w . jav a 2 s . c o m*/ public String buildLoginUrl() { final GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl(); return url.setRedirectUri(CALLBACK_URI).setState(stateToken).build(); }
From source file:com.youtube.apiv3.YoutubeManager.java
private static void buildLoginUrl(InputStream secrets) throws IOException { List<String> scopes = new ArrayList(); scopes.add("https://www.googleapis.com/auth/youtube"); scopes.add("https://www.googleapis.com/auth/youtube.upload"); // Load client secrets. Reader clientSecretReader = new InputStreamReader(secrets); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader); // This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore} FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory( new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY)); DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore("uploadvideo"); flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes) .setCredentialDataStore(datastore).build(); GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl(); loginUrl = url.setRedirectUri(CALLBACK_URI).setAccessType("offline").build(); clientSecretReader.close();//from w w w . ja va 2 s . c o m secrets.close(); }
From source file:eu.trentorise.smartcampus.permissionprovider.auth.google.GoogleAuthHelper.java
License:Apache License
/** * Builds a login URL based on client ID, secret, callback URI, and scope. *//*from w w w . jav a 2s .com*/ public GoogleAuthorizationCodeRequestUrl buildLoginUrl() { final GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl(); return url.setRedirectUri(callbackURI).setState(generateStateToken()); }
From source file:gamepub.beans.GoogleAuthorizationBean.java
@PostConstruct public void buildUserUrl() { flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientId, clientSecret, SCOPE) .build();/*from w ww .j a v a 2 s .co m*/ final GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl(); userUrl = url.setRedirectUri(redirectUri).build(); }