lumpynose

google oauth2 redirect

Jan 5th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.89 KB | None | 0 0
  1.         Credential credential = new Credential.Builder(BearerToken.authorizationHeaderAccessMethod())
  2.         .addRefreshListener(new CredentialStoreRefreshListener(stripesActionBeanContext.getUser().getUserId(),
  3.                 new AppEngineCredentialStore()))
  4.         .setJsonFactory(new JacksonFactory())
  5.         .setTokenServerUrl(new GenericUrl("https://accounts.google.com/o/oauth2/token"))
  6.         .setClientAuthentication(
  7.                 new ClientParametersAuthentication(
  8.                         Constants.GOOGLE_API_KEY,
  9.                         Constants.GOOGLE_API_SECRET))
  10.         .setTransport(new UrlFetchTransport())
  11.         .build();
  12.  
  13.         AppEngineCredentialStore appEngineCredentialStore =
  14.             new AppEngineCredentialStore();
  15.  
  16.         if (! appEngineCredentialStore.load(stripesActionBeanContext.getUser().getUserId(), credential)) {
  17.             log.debug("calling AuthorizationCodeRequestUrl");
  18.  
  19.             String url =
  20.                     new AuthorizationCodeRequestUrl("https://accounts.google.com/o/oauth2/auth",
  21.                             Constants.GOOGLE_API_KEY)
  22.                         .setRedirectUri(Constants
  23.                                 .googleOJCCallbackUri(stripesActionBeanContext.getRequest().getScheme(),
  24.                                         stripesActionBeanContext.getRequest().getServerName(),
  25.                                         stripesActionBeanContext.getRequest().getServerPort()))
  26.                         .setScopes(Collections.singletonList("https://www.googleapis.com/auth/urlshortener"))
  27.                         .setState(stripesActionBeanContext.getRequest().getRequestURI())
  28.                         .set("approval_prompt", "force")
  29.                         .set("access_type", "offline")
  30.                         .build();
  31.  
  32.             log.debug("redirect url: {}", url);
  33.  
  34.             return (new RedirectResolution(url));
  35.         }
Add Comment
Please, Sign In to add comment