當前位置: 首頁>>代碼示例>>Java>>正文


Java GoogleAuthorizationCodeFlow.newAuthorizationUrl方法代碼示例

本文整理匯總了Java中com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow.newAuthorizationUrl方法的典型用法代碼示例。如果您正苦於以下問題:Java GoogleAuthorizationCodeFlow.newAuthorizationUrl方法的具體用法?Java GoogleAuthorizationCodeFlow.newAuthorizationUrl怎麽用?Java GoogleAuthorizationCodeFlow.newAuthorizationUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow的用法示例。


在下文中一共展示了GoogleAuthorizationCodeFlow.newAuthorizationUrl方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRefreshToken

import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; //導入方法依賴的package包/類
@SuppressWarnings("unused")
private static String getRefreshToken() throws IOException {
    String client_id = System.getenv("PICASSA_CLIENT_ID");
    String client_secret = System.getenv("PICASSA_CLIENT_SECRET");
    
    // Adapted from http://stackoverflow.com/a/14499390/1447621
    String redirect_uri = "http://localhost";
    String scope = "http://picasaweb.google.com/data/";
    List<String> scopes;
    HttpTransport transport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();

    scopes = new LinkedList<String>();
    scopes.add(scope);
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(transport, jsonFactory, client_id, client_secret, scopes).build();
    GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl();
    url.setRedirectUri(redirect_uri);
    url.setApprovalPrompt("force");
    url.setAccessType("offline");
    String authorize_url = url.build();
   
    // paste into browser to get code
    System.out.println("Put this url into your browser and paste in the access token:");
    System.out.println(authorize_url);
    
    Scanner scanner = new Scanner(System.in);
    String code = scanner.nextLine();
    scanner.close();

    flow = new GoogleAuthorizationCodeFlow.Builder(transport, jsonFactory, client_id, client_secret, scopes).build();
    GoogleTokenResponse res = flow.newTokenRequest(code).setRedirectUri(redirect_uri).execute();
    String refreshToken = res.getRefreshToken();
    String accessToken = res.getAccessToken();

    System.out.println("refresh:");
    System.out.println(refreshToken);
    System.out.println("access:");
    System.out.println(accessToken);
    return refreshToken;
}
 
開發者ID:DeveloperLiberationFront,項目名稱:Pdf-Reviewer,代碼行數:41,代碼來源:ImageUtils.java

示例2: execute

import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; //導入方法依賴的package包/類
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();

		GoogleAuthorizationCodeRequestUrl
			googleAuthorizationCodeRequestUrl = flow.newAuthorizationUrl();

		googleAuthorizationCodeRequestUrl.setRedirectUri(redirectUri);

		String url = googleAuthorizationCodeRequestUrl.build();

		response.sendRedirect(url);
	}
	else if (cmd.equals("token")) {
		HttpSession session = request.getSession();

		String code = ParamUtil.getString(request, "code");

		if (Validator.isNotNull(code)) {
			Credential credential = exchangeCode(code, redirectUri);

			Userinfo 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;
}
 
開發者ID:sergiogonzalez,項目名稱:google-login-hook,代碼行數:60,代碼來源:GoogleOAuth.java


注:本文中的com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow.newAuthorizationUrl方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。