private void auth() throws IOException {
    // If you choose to use a callback, "oauth_verifier" will be the return value by Twitter
    // (request param)
    Scanner in = new Scanner(System.in);

    System.out.println("=== Twitter's OAuth Workflow ===");
    System.out.println();
    // Obtain the Request Token
    System.out.println("Fetching the Request Token...");
    Token requestToken = service.getRequestToken();
    System.out.println("Got the Request Token!");
    System.out.println();

    System.out.println("Go authorize here, please:");
    System.out.println(service.getAuthorizationUrl(requestToken));
    System.out.println("And paste the verifier here");
    System.out.print(">>");
    Verifier verifier = new Verifier(in.nextLine());
    System.out.println();

    // Trade the Request Token and Verfier for the Access Token
    System.out.println("Trading the Request Token for an Access Token...");
    accessToken = service.getAccessToken(requestToken, verifier);
    System.out.println("Got the Access Token!");
    serializeToken();
    System.out.println("Cached token.");
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest
   * , javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    log.info("GET got parameters: " + req.getParameterMap());
    log.info("HTTP Session: " + req.getSession().getAttributeNames());

    HttpSession httpsession = req.getSession();

    try {

      OAuth2Provider provider =
          OAuth2Provider.valueOf((String) httpsession.getAttribute("oauth.service"));
      log.info("Got provider: " + provider);

      String oauthVerifier = "";
      Token requestToken = null;
      Token accessToken = new Token("", provider.getSecret());
      OAuthService service = provider.getOAuthService();

      if (provider.getApi() instanceof DefaultApi20) {
        oauthVerifier = req.getParameter("code");
        log.info("got OAuth 2.0 authorization code: " + oauthVerifier);

      } else if (provider.getApi() instanceof DefaultApi10a) {
        oauthVerifier = req.getParameter("oauth_verifier");
        log.info("got OAuth 1.0a verifier: " + oauthVerifier);
        requestToken =
            req.getParameter("oauth_token") != null
                ? new Token((String) req.getParameter("oauth_token"), provider.getSecret())
                : (Token) httpsession.getAttribute("oauth.requestToken");
      }

      Verifier verifier = new Verifier(oauthVerifier);
      accessToken = service.getAccessToken(requestToken, verifier);
      log.info(
          "Got a OAuth access token: " + accessToken.getToken() + ", " + accessToken.getSecret());

      Cookie accessTokenCookie = new Cookie("oauth.accessToken", accessToken.getToken());
      accessTokenCookie.setMaxAge(14 * 24 * 60 * 60);
      accessTokenCookie.setPath("/");
      resp.addCookie(accessTokenCookie);
      Cookie serviceCookie = new Cookie("oauth.service", provider.toString());
      serviceCookie.setPath("/");
      serviceCookie.setMaxAge(14 * 24 * 60 * 60);
      resp.addCookie(serviceCookie);
      Cookie secretCookie = new Cookie("oauth.secret", accessToken.getSecret());
      secretCookie.setPath("/");
      secretCookie.setMaxAge(14 * 24 * 60 * 60);
      resp.addCookie(secretCookie);

      resp.sendRedirect((String) req.getSession().getAttribute("http.referer"));

    } catch (Exception e) {
      log.log(Level.WARNING, e.getLocalizedMessage(), e);
    }
  }
  public static void main(String[] args) {

    String apiKey = "your_app_id";
    String apiSecret = "your_api_secret";

    OAuthService service =
        new ServiceBuilder() //
            .provider(BitlyApi.class) //
            .apiKey(apiKey) //
            .apiSecret(apiSecret) //
            .callback("http://localhost:8080/oauth_callback") //
            .debug() //
            .build();
    Scanner in = new Scanner(System.in);

    System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
    System.out.println();

    // Obtain the Authorization URL
    System.out.println("Fetching the Authorization URL...");
    String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
    System.out.println("Got the Authorization URL!");
    System.out.println("Now go and authorize Scribe here:");
    System.out.println(authorizationUrl);
    System.out.println("And paste the authorization code here");
    System.out.print(">>");
    Verifier verifier = new Verifier(in.nextLine());
    System.out.println();

    // Trade the Request Token and Verfier for the Access Token
    System.out.println("Trading the Request Token for an Access Token...");
    Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
    System.out.println("Got the Access Token!");
    System.out.println("(if your curious it looks like this: " + accessToken + " )");
    System.out.println();

    // Now let's go and ask for a protected resource!
    System.out.println("Now we're going to access a protected resource...");
    OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
    service.signRequest(accessToken, request);
    Response response = request.send();
    System.out.println("Got it! Lets see what we found...");
    System.out.println();
    System.out.println(response.getCode());
    System.out.println(response.getBody());

    System.out.println();
    System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
  }
  protected void updateAccessToken(RenderRequest renderRequest, String oAuthVerifier)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Token requestToken = oAuthManager.getRequestToken(themeDisplay.getUser());

    OAuthService oAuthService = oAuthManager.getOAuthService();

    Token accessToken = oAuthService.getAccessToken(requestToken, new Verifier(oAuthVerifier));

    oAuthManager.updateAccessToken(themeDisplay.getUser(), accessToken);

    oAuthManager.deleteRequestToken(themeDisplay.getUser());
  }
Example #5
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;
 }
  public static void authenticateEvernote(
      RenderRequest renderRequest, PortletSession portletSession, ThemeDisplay themeDisplay)
      throws OAuthException {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(renderRequest);
    String authorizationUrl = StringPool.BLANK;

    try {

      OAuthService service = getOAuthService(request, themeDisplay);

      if (PortalUtil.getOriginalServletRequest(request).getParameter(OAUTH_VERIFIER) == null) {
        // Send an OAuth message to the Provider asking for a new Request
        // Token because we don't have access to the current user's account.
        Token scribeRequestToken = service.getRequestToken();

        portletSession.setAttribute(REQUEST_TOKEN, scribeRequestToken.getToken());
        portletSession.setAttribute(REQUEST_TOKEN_SECRET, scribeRequestToken.getSecret());

        authorizationUrl = EVERNOTE_SERVICE.getAuthorizationUrl(scribeRequestToken.getToken());

      } else {
        // Send an OAuth message to the Provider asking to exchange the
        // existing Request Token for an Access Token
        Token scribeRequestToken =
            new Token(
                portletSession.getAttribute(REQUEST_TOKEN).toString(),
                portletSession.getAttribute(REQUEST_TOKEN_SECRET).toString());

        Verifier scribeVerifier =
            new Verifier(
                PortalUtil.getOriginalServletRequest(request).getParameter(OAUTH_VERIFIER));

        Token scribeAccessToken = service.getAccessToken(scribeRequestToken, scribeVerifier);

        EvernoteAuth evernoteAuth =
            EvernoteAuth.parseOAuthResponse(EVERNOTE_SERVICE, scribeAccessToken.getRawResponse());

        portletSession.setAttribute(ACCESS_TOKEN, evernoteAuth.getToken());
      }

    } catch (Exception e) {
      throw new OAuthException(e);
    }

    renderRequest.setAttribute(AUTHORIZATION_URL, authorizationUrl);
  }
Example #7
0
  public static void main(String[] args) {
    // Replace these with your client id and secret
    final String clientId = "your client id";
    final String clientSecret = "your client secret";
    final OAuthService service =
        new ServiceBuilder()
            .provider(TutByApi.class)
            .apiKey(clientId)
            .apiSecret(clientSecret)
            .grantType("authorization_code")
            .callback("http://www.example.com/oauth_callback/")
            .build();
    final Scanner in = new Scanner(System.in, "UTF-8");

    System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
    System.out.println();

    System.out.println("Fetching the Authorization URL...");
    final String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
    System.out.println("Got the Authorization URL!");
    System.out.println("Now go and authorize SubScribe here:");
    System.out.println(authorizationUrl);
    System.out.println("And paste the authorization code here");
    System.out.print(">>");
    final Verifier verifier = new Verifier(in.nextLine());
    System.out.println();

    // Trade the Request Token and Verfier for the Access Token
    System.out.println("Trading the Request Token for an Access Token...");
    final Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
    System.out.println("Got the Access Token!");
    System.out.println("(if your curious it looks like this: " + accessToken + " )");
    System.out.println();

    // Now let's go and ask for a protected resource!
    System.out.println("Now we're going to access a protected resource...");
    final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
    service.signRequest(accessToken, request);
    final Response response = request.send();
    System.out.println("Got it! Lets see what we found...");
    System.out.println();
    System.out.println(response.getCode());
    System.out.println(response.getBody());

    System.out.println();
    System.out.println("Thats it man! Go and build something awesome with SubScribe! :)");
  }
Example #8
0
  public static void main(String[] args) {
    OAuthService service =
        new ServiceBuilder()
            .provider(Layer7Api.class)
            .apiKey("Consumer")
            .apiSecret("Secret")
            .build();
    Scanner in = new Scanner(System.in);

    System.out.println("=== Layer7's OAuth Toolkit 1.0 Workflow ===");
    System.out.println();

    // Obtain the Request Token
    System.out.println("Fetching the Request Token...");
    Token requestToken = service.getRequestToken();
    System.out.println("Got the Request Token!");
    System.out.println();

    System.out.println("Now go and authorize Scribe here:");
    System.out.println(service.getAuthorizationUrl(requestToken));
    System.out.println("And paste the verifier here");
    System.out.print(">>");
    Verifier verifier = new Verifier(in.nextLine());
    System.out.println();

    // Trade the Request Token and Verifier for the Access Token
    System.out.println("Trading the Request Token for an Access Token...");
    Token accessToken = service.getAccessToken(requestToken, verifier);
    System.out.println("Got the Access Token!");
    System.out.println("(if your curious it looks like this: " + accessToken + " )");
    System.out.println();

    // Now let's go and ask for a protected resource!
    System.out.println("Now we're going to access a protected resource...");
    OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URI);
    service.signRequest(accessToken, request);
    Response response = request.send();
    System.out.println("Got it! Lets see what we found...");
    System.out.println();
    System.out.println(response.getBody());

    System.out.println();
    System.out.println(
        "Thats it man! Go and build something awesome with Scribe and Layer 7's OAuth Toolkit! :)");
  }
Example #9
0
  public static void main(String[] args) {
    String apiKey = "357304594324208";
    String apiSecret = "8eca9a549d5c3631752c4d472a5814c1";
    OAuthService service =
        new ServiceBuilder()
            .provider(FacebookApi.class)
            .apiKey(apiKey)
            .apiSecret(apiSecret)
            .callback("https://sharp-night-6938.herokuapp.com/oauth_callback/")
            .build();
    Scanner in = new Scanner(System.in);

    System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
    System.out.println();

    // Obtain the Authorization URL
    System.out.println("Fetching the Authorization URL...");
    String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);
    System.out.println("Got the Authorization URL!");
    System.out.println("Now go and authorize Scribe here:");
    System.out.println(authorizationUrl);
    System.out.println("And paste the authorization code here");
    System.out.print(">>");
    Verifier verifier = new Verifier(in.nextLine());
    System.out.println();

    // Trade the Request Token and Verfier for the Access Token
    System.out.println("Trading the Request Token for an Access Token...");
    Token accessToken = service.getAccessToken(EMPTY_TOKEN, verifier);
    System.out.println("Got the Access Token!");
    System.out.println("(if your curious it looks like this: " + accessToken + " )");
    System.out.println();

    // Now let's go and ask for a protected resource!
    System.out.println("Now we're going to access a protected resource...");
    OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
    service.signRequest(accessToken, request);
    Response response = request.send();
    System.out.println("Got it! Lets see what we found...");
    System.out.println();
    System.out.println(response.getCode());
    System.out.println(response.getBody());

    System.out.println();
  }
  public static void main(String[] args) throws MalformedURLException {
    OAuthService service =
        new ServiceBuilder()
            .provider(FoursquareApi.class)
            .apiKey("FEGFXJUFANVVDHVSNUAMUKTTXCP1AJQD53E33XKJ44YP1S4I")
            .apiSecret("AYWKUL5SWPNC0CTQ202QXRUG2NLZYXMRA34ZSDW4AUYBG2RC")
            .build();
    Scanner in = new Scanner(System.in);

    System.out.println("=== Foursquare's OAuth Workflow ===");
    System.out.println();

    // Obtain the Request Token
    System.out.println("Fetching the Request Token...");
    Token requestToken = service.getRequestToken();
    System.out.println("Got the Request Token!");
    System.out.println();

    System.out.println("Now go and authorize Scribe here:");
    System.out.println(service.getAuthorizationUrl(requestToken));
    System.out.println("And paste the verifier here");
    System.out.print(">>");
    Verifier verifier = new Verifier(in.nextLine());
    System.out.println();

    // Trade the Request Token and Verfier for the Access Token
    System.out.println("Trading the Request Token for an Access Token...");
    Token accessToken = service.getAccessToken(requestToken, verifier);
    System.out.println("Got the Access Token!");
    System.out.println("(if your curious it looks like this: " + accessToken + " )");
    System.out.println();

    // Now let's go and ask for a protected resource!
    System.out.println("Now we're going to access a protected resource...");
    OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
    service.signRequest(accessToken, request);
    Response response = request.send();
    System.out.println("Got it! Lets see what we found...");
    System.out.println();
    System.out.println(response.getBody());

    System.out.println();
    System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
  }
  @HandlesEvent("callback")
  public Resolution callback() {
    logger.debug("El codigo para verificar es: {}", oauth_verifier);
    // coge request token
    OAuthService service = googleServiceProvider.getService();
    Token requestToken =
        (Token)
            getContext()
                .getRequest()
                .getSession()
                .getAttribute(ATTR_OAUTH_REQUEST_TOKEN + "Google");

    // coge access token
    Verifier verifier = new Verifier(oauth_verifier);
    Token accessToken = service.getAccessToken(requestToken, verifier);

    logger.debug("El access token es: {}", accessToken.getRawResponse());

    // guarda access token en session
    getContext()
        .getRequest()
        .getSession()
        .setAttribute(ATTR_OAUTH_ACCESS_TOKEN + "Google", accessToken);

    // coge perfil usuario
    OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
    logger.debug("Se va a conectar al servicio de google: ");
    service.signRequest(accessToken, oauthRequest);
    Response oauthResponse = oauthRequest.send();
    String body = oauthResponse.getBody();

    ObjectMapper mapper = new ObjectMapper();
    try {
      respuestaJson = mapper.readValue(body, new TypeReference<Map<String, Object>>() {});

    } catch (IOException e) {
      getContext()
          .getValidationErrors()
          .addGlobalError(new SimpleError("error.excepcion.jackson", e.getMessage()));
    }

    logger.debug("La respuesta  body: {}", oauthResponse.getBody());
    return new ForwardResolution("/WEB-INF/jsp/google.jsp");
  }
  public String doFinish() {
    // now get the access token
    Verifier verifier = new Verifier(request.getParameter("oauth_verifier"));
    Token requestToken = (Token) request.getSession().getAttribute(SESSION_KEY_REQUEST_TOKEN);

    if (requestToken == null) {
      log.debug(
          "Request token is NULL. It has been removed in the previous attempt of adding organization. Now we will stop.");
      return getRedirect(
          "ConfigureDvcsOrganizations.jspa?atl_token=" + CustomStringUtils.encode(getXsrfToken()));
    }

    request.getSession().removeAttribute(SESSION_KEY_REQUEST_TOKEN);

    OAuthService service = createOAuthScribeService();
    Token accessTokenObj = service.getAccessToken(requestToken, verifier);
    accessToken = BitbucketOAuthAuthentication.generateAccessTokenString(accessTokenObj);

    httpClientProvider.closeIdleConnections();

    return doAddOrganization();
  }
  public static void main(String[] args) {
    // Replace these with your own api key and secret

    String apiKey = "your_app_id";
    String apiSecret = "your_api_secret";
    String callbackURL = "your_call_back";
    OAuthService service =
        new ServiceBuilder()
            .provider(FacebookApi.class)
            .apiKey(apiKey)
            .apiSecret(apiSecret)
            .callback(callbackURL)
            .grantType(OAuthConstants.CLIENT_CREDENTIALS)
            .build();

    System.out.println("=== " + NETWORK_NAME + "'s OAuth Workflow ===");
    System.out.println();
    System.out.println(
        "Getting an access Token with Client Credentials (a.k.a App Login as Facebook defines)");
    Token accessToken = service.getAccessToken(EMPTY_TOKEN, null);
    System.out.println("Got the Access Token!");
    System.out.println("(if your curious it looks like this: " + accessToken + " )");
    System.out.println();

    // Now let's go and ask for a protected resource!
    System.out.println("Now we're going to access a protected resource...");
    OAuthRequest request =
        new OAuthRequest(Verb.GET, String.format(PROTECTED_RESOURCE_URL, apiKey));
    service.signRequest(accessToken, request);
    Response response = request.send();
    System.out.println("Got it! Lets see what we found...");
    System.out.println();
    System.out.println(response.getCode());
    System.out.println(response.getBody());

    System.out.println();
    System.out.println("Thats it man! Go and build something awesome with Scribe! :)");
  }
Example #14
0
  public OAuthToken getAccessToken(
      String clientId, String clientSecret, String authorizationCode, OAuthToken requestToken) {
    OAuthToken token = null;

    try {
      OAuthService service =
          new ServiceBuilder()
              .provider(LinkedInApi.class)
              .apiKey(clientId)
              .apiSecret(clientSecret)
              .build();
      Verifier verifier = new Verifier(authorizationCode);
      Token reqToken = new Token(requestToken.getToken(), requestToken.getTokenSecret());
      Token accessToken = service.getAccessToken(reqToken, verifier);
      token = new OAuthToken();
      token.setToken(accessToken.getToken());
      token.setTokenSecret(accessToken.getSecret());
    } catch (Exception e) {
      log.error("Error getting AccessToken", e);
    }

    return token;
  }
  /** Callback. */
  public static void callback() {
    // Get Service
    OAuthService service = getServiceNoCallback();

    // Get Query String Token and Verifier
    Logger.info("LinkedIn Callback - Params: " + params);
    String oauthToken = params.get("oauth_token");
    String oauthVerifier = params.get("oauth_verifier");
    Verifier verifier = new Verifier(oauthVerifier);
    Logger.info("Token: " + oauthToken);
    Logger.info("Verifier: " + oauthVerifier);

    // Request Access Token
    Token accessToken =
        service.getAccessToken(
            new Token(oauthToken, Cache.get(oauthToken, String.class)), verifier);

    // Log Debug
    Logger.info("LinkedIn Access Token: " + accessToken);

    // Check Response
    if (accessToken != null && accessToken.getToken() != null) {
      // Get Profile Details
      String url =
          "http://api.linkedin.com/v1/people/~:(id,first-name,last-name,industry,picture-url,headline)";
      OAuthRequest request = new OAuthRequest(Verb.GET, url);
      service.signRequest(accessToken, request);
      Response response = request.send();
      String responseBody = response.getBody();
      Logger.info("Response Body: %s", responseBody);

      // Check Status
      if (response == null || response.getCode() != 200) {
        String msg = "";
        if (response != null) {
          msg = response.getBody();
        }
        throw new UnexpectedException(msg);
      }

      // Parse XML Response
      Map<String, String> data = new HashMap<String, String>();
      Document doc = XML.getDocument(responseBody);
      Node person = doc.getElementsByTagName("person").item(0);
      NodeList list = person.getChildNodes();
      for (int i = 0; i < list.getLength(); i++) {
        Node n = list.item(i);
        data.put(n.getNodeName(), n.getTextContent());
      }

      // Load Data Object
      LinkedInProfile p =
          new LinkedInProfile(
              data.get("id"),
              data.get("first-name"),
              data.get("last-name"),
              data.get("industry"),
              data.get("picture-url"),
              data.get("headline"),
              accessToken.getToken());

      // Log Debug
      Logger.info("Profile Data Map: %s", data);
      Logger.info("Profile Data Object: %s", p);

      // Do Callback to Calling App
      try {
        Class model = Class.forName(getModel());
        Method method =
            model.getMethod("linkedinOAuthCallback", new Class[] {LinkedInProfile.class});
        if (Modifier.isStatic(method.getModifiers())) {
          method.invoke(null, p);

        } else {
          throw new UnexpectedException("Method linkedinOAuthCallback method needs to be static");
        }
      } catch (ClassNotFoundException e) {
        throw new UnexpectedException("Cannot find your model class " + getModel());

      } catch (NoSuchMethodException e) {
        throw new UnexpectedException(
            "Model class "
                + getModel()
                + " must provide a method with this signature: [public static void linkedinOAuthCallback(play.modules.linkedin.LinkedInProfile o)]");

      } catch (IllegalAccessException e) {
        throw new UnexpectedException(
            "Module linkedin does not have access to call your model's linkedinOAuthCallback(play.modules.linkedin.LinkedInProfile o)");

      } catch (InvocationTargetException e) {
        throw new UnexpectedException(
            "Module linkedin encountered an error while calling your model's linkedinOAuthCallback(play.modules.linkedin.LinkedInProfile o): "
                + e.getMessage());
      }
    } else {
      throw new UnexpectedException("Access Token Unavailable");
    }

    // Redirect to Landing Page
    redirect(getLandUrl());
  }
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    if (request.getParameter("oauth_problem") != null) {
      if (request.getParameter("oauth_problem").equals("user_refused"))
        response.sendRedirect("refuse.html");
    } else {
      OAuthService service;
      Token requestToken, accessToken;
      OAuthRequest requestLink;
      org.scribe.model.Response responseLink;
      DBHandler db = new DBHandler();

      service =
          new ServiceBuilder()
              .provider(LinkedInApi.class)
              .apiKey("754z46slfke0xm")
              .apiSecret("Jm46YNdPTb2toxoY")
              .build();

      String oAuthToken = request.getParameter("oauth_token");
      String oAuthVerifier = request.getParameter("oauth_verifier");

      String[] data = db.getData(oAuthToken);
      String oAuthSecret = data[1];
      String roomId = data[2];
      String email = data[3];

      requestToken = new Token(oAuthToken, oAuthSecret);

      Verifier v = new Verifier(oAuthVerifier);
      accessToken = service.getAccessToken(requestToken, v);

      System.out.println("\n\n\n\n\n" + accessToken + "\n\n\n\n\n");

      db.setAccessData(email, accessToken.getToken(), accessToken.getSecret());

      requestLink = new OAuthRequest(Verb.GET, "https://api.linkedin.com/v1/people/~?format=json");
      service.signRequest(accessToken, requestLink); // the access token
      // from step 4
      responseLink = requestLink.send();

      if (responseLink.getCode() != 401) {
        JSONObject j1 = new JSONObject(responseLink.getBody());

        TeamchatAPI api = WebAppTeamChatAPI.getTeamchatAPIInstance(getServletConfig());
        api.perform(
            api.context()
                .byId(roomId)
                .post(
                    new PrimaryChatlet()
                        .setQuestionHtml(
                            "Now you are authorized to send linkedin updates from teamchat"
                                + "<br/><b>Use following keywords -</b><br/><ul>"
                                + "<li>'profile' - Get Profile Information</li>"
                                + "<li>'post' - Post on LinkedIn</li></ol>"
                                + "<li>'reset' - Remove your account from teamchat</li></ul>")));

        request.setAttribute("name", j1.getString("firstName") + " " + j1.getString("lastName"));
        RequestDispatcher rd = request.getRequestDispatcher("Auth.jsp");
        rd.forward(request, response);
      } else response.sendRedirect("error.html");
    }
  }
Example #17
0
 /**
  * Use this when the user has a code from the browser. This browser-code can be exchanged for a
  * accessToken. The accessToken is used to use further API-calls.
  *
  * @param code the code from the browser
  * @return accessToken
  */
 public String loginWithBrowserCode(String code) {
   Verifier v = new Verifier(code);
   Token accessToken = service.getAccessToken(null, v);
   accessTokenString = accessToken.getToken();
   return accessTokenString;
 }
 public String getAccessToken(String code) {
   Verifier verifier = new Verifier(code);
   return oAuthService.getAccessToken(EMPTY_REQUEST_TOKEN, verifier).getToken();
 }
Example #19
0
 protected void requestAccessToken() {
   mAccessToken = mOauthService.getAccessToken(mRequestToken, mVerifier);
 }
 @Override
 public Token getAccessToken(Token requestToken, Verifier verifier) {
   return oAuthService.getAccessToken(requestToken, verifier);
 }
Example #21
0
 public Token getAccessToken(Token requestToken, String verify) {
   OAuthService service =
       new ServiceBuilder().provider(MaxCDNApi.class).apiKey(key).apiSecret(secret).build();
   return service.getAccessToken(requestToken, new Verifier(verify));
 }