@RequestMapping(value = "/upgradeToken")
  public String upgradeToken(HttpServletRequest request, HttpServletResponse response)
      throws OAuthException, OAuthMessageSignerException, OAuthNotAuthorizedException,
          OAuthExpectationFailedException, OAuthCommunicationException {
    OAuthConsumer consumer =
        (OAuthConsumer) request.getSession().getAttribute(FRESHBOOKS_OAUTH_CONSUMER);
    OAuthProvider provider =
        (OAuthProvider) request.getSession().getAttribute(FRESHBOOKS_OAUTH_PROVIDER);
    String verifier = request.getParameter("oauth_verifier");
    provider.retrieveAccessToken(consumer, verifier);
    Guest guest = AuthHelper.getGuest();

    final Connector connector = Connector.getConnector("freshbooks");
    final ApiKey apiKey = guestService.createApiKey(guest.getId(), connector);

    guestService.setApiKeyAttribute(apiKey, "accessToken", consumer.getToken());
    guestService.setApiKeyAttribute(apiKey, "tokenSecret", consumer.getTokenSecret());

    return "redirect:/app/from/" + connector.getName();
  }
Ejemplo n.º 2
0
 public boolean checkAuthorization(GuestService guestService, long guestId) {
   ApiKey apiKey = guestService.getApiKey(guestId, Connector.getConnector("toodledo"));
   return apiKey != null;
 }