Example #1
0
  /**
   * Constructor.
   *
   * @param pageParameters contain response details from the OAuth server
   * @throws URISyntaxException the response details contain invalid URIs
   */
  public OAuthPage(PageParameters pageParameters) throws URISyntaxException {
    super(pageParameters);

    MySession session = MySession.get();
    PortalApplication app = (PortalApplication) getApplication();

    if (session.getMyExpAccessToken() == null) {
      OAuthService service =
          MyExpApi.getOAuthService(
              app.getMyExpConsumerKey(), app.getMyExpConsumerSecret(), app.getCallbackURL());
      Token token = retrieveMyExpAccessToken(pageParameters, service);
      session.setMyExpAccessToken(token);
      if (token != null) {
        LOG.info("Successfully received myExperiment access token");
      }
    }
    continueToOriginalDestination();
    LOG.warn("Could not find the original destination");
    throw new RestartResponseException(getApplication().getHomePage());
  }
Example #2
0
 /**
  * Retrieve an OAuth 1.0 access token from the myExperiment response.
  *
  * @param pageParameters page params
  * @param service myExperiment OAuth service instance
  * @return the access token
  */
 private Token retrieveMyExpAccessToken(PageParameters pageParameters, OAuthService service) {
   Token accessToken = null;
   if (!pageParameters.get(MyExpApi.OAUTH_VERIFIER).isEmpty()) {
     Verifier verifier = new Verifier(pageParameters.get(MyExpApi.OAUTH_VERIFIER).toString());
     Token requestToken = MySession.get().getRequestToken();
     LOG.debug(
         "Request token: "
             + requestToken.toString()
             + " verifier: "
             + verifier.getValue()
             + " service: "
             + service.getAuthorizationUrl(requestToken));
     accessToken = service.getAccessToken(requestToken, verifier);
   }
   return accessToken;
 }