Ejemplo n.º 1
0
void
cb_user_stream_set_proxy_data (CbUserStream *self,
                               const char   *token,
                               const char   *token_secret)
{
  oauth_proxy_set_token (OAUTH_PROXY (self->proxy), token);
  oauth_proxy_set_token_secret (OAUTH_PROXY (self->proxy), token_secret);

  self->proxy_data_set = TRUE;
}
Ejemplo n.º 2
0
static void
online_notify (gboolean online, gpointer user_data)
{
  SwServiceTwitter *twitter = (SwServiceTwitter *)user_data;
  SwServiceTwitterPrivate *priv = twitter->priv;

  SW_DEBUG (TWITTER, "Online: %s", online ? "yes" : "no");

  /* Clear the token and token secret stored inside the proxy */
  oauth_proxy_set_token (OAUTH_PROXY (priv->proxy), NULL);
  oauth_proxy_set_token_secret (OAUTH_PROXY (priv->proxy), NULL);

  if (online) {
    if (priv->username && priv->password) {
      RestProxyCall *call;

      SW_DEBUG (TWITTER, "Getting token");

      /*
       * Here we use xAuth to transform a username and password into a OAuth
       * access token.
       *
       * http://apiwiki.twitter.com/Twitter-REST-API-Method:-oauth-access_token-for-xAuth
       */
      call = rest_proxy_new_call (priv->proxy);
      rest_proxy_call_set_function (call, "oauth/access_token");
      rest_proxy_call_add_params (call,
                                  "x_auth_mode", "client_auth",
                                  "x_auth_username", priv->username,
                                  "x_auth_password", priv->password,
                                  NULL);
      rest_proxy_call_async (call, _oauth_access_token_cb, (GObject*)twitter, NULL, NULL);
      /* Set offline for now and wait for access_token_cb to return */
      priv->credentials = OFFLINE;
    } else {
      priv->credentials = OFFLINE;
    }
  } else {
    g_free (priv->user_id);

    if (priv->twitpic_proxy) {
      g_object_unref (priv->twitpic_proxy);
      priv->twitpic_proxy = NULL;
    }

    priv->user_id = NULL;
    priv->credentials = OFFLINE;

    sw_service_emit_capabilities_changed ((SwService *)twitter,
                                          get_dynamic_caps ((SwService *)twitter));
  }
}
Ejemplo n.º 3
0
static void
_oauth_access_token_cb (RestProxyCall *call,
                        const GError  *error,
                        GObject       *weak_object,
                        gpointer       userdata)
{
  SwService *service = SW_SERVICE (weak_object);
  SwServiceTwitter *twitter = SW_SERVICE_TWITTER (service);

  if (error) {
    sanity_check_date (call);
    g_message ("Error: %s", error->message);

    twitter->priv->credentials = CREDS_INVALID;
    sw_service_emit_capabilities_changed (service, get_dynamic_caps (service));

    return;
  }

  oauth_proxy_call_parse_token_reponse (OAUTH_PROXY_CALL (call));

  SW_DEBUG (TWITTER, "Got OAuth access tokens");

  g_object_unref (call);

  /* Create a TwitPic proxy using OAuth Echo */
  twitter->priv->twitpic_proxy = oauth_proxy_new_echo_proxy
    (OAUTH_PROXY (twitter->priv->proxy),
     "https://api.twitter.com/1/account/verify_credentials.json",
     "http://api.twitpic.com/2/", FALSE);

  /*
   * Despite the fact we know the credentials are fine, we check them again to
   * get the user ID and avatar.
   *
   * http://apiwiki.twitter.com/Twitter-REST-API-Method:-account verify_credentials
   */
  call = rest_proxy_new_call (twitter->priv->proxy);
  rest_proxy_call_set_function (call, "1/account/verify_credentials.xml");
  rest_proxy_call_async (call, verify_cb, (GObject*)twitter, NULL, NULL);
}
Ejemplo n.º 4
0
int
main (int argc, char **argv)
{
  RestProxy *proxy;
  RestProxyCall *call;
  GError *error = NULL;
  char pin[256];
  RestXmlParser *parser;
  RestXmlNode *root, *node;

  g_type_init ();

  /* Create the proxy */
  proxy = oauth_proxy_new (/* Consumer Key */
                           "NmUm6hxQ9a4u",
                           /* Consumer Secret */
                           "t4FM7LiUeD4RBwKSPa6ichKPDh5Jx4kt",
                           /* FireEagle endpoint */
                           "https://fireeagle.yahooapis.com/", FALSE);

  /* First stage authentication, this gets a request token. */
  if (!oauth_proxy_request_token (OAUTH_PROXY (proxy),
                                  "oauth/request_token",
                                  "oob",
                                  &error))
    g_error ("Cannot request token: %s", error->message);

  /* From the token construct a URL for the user to visit */
  g_print ("Go to https://fireeagle.yahoo.net/oauth/authorize?oauth_token=%s then enter the verification code\n",
           oauth_proxy_get_token (OAUTH_PROXY (proxy)));

  /* Read the PIN */
  fgets (pin, sizeof (pin), stdin);
  g_strchomp (pin);

  /* Second stage authentication, this gets an access token. */
  if (!oauth_proxy_access_token (OAUTH_PROXY (proxy),
                                 "oauth/access_token",
                                 pin,
                                 &error))
    g_error ("Cannot request token: %s", error->message);

  /* Get the user's current location */
  call = rest_proxy_new_call (proxy);
  rest_proxy_call_set_function (call, "api/0.1/user");

  if (!rest_proxy_call_run (call, NULL, &error))
    g_error ("Cannot make call: %s", error->message);

  parser = rest_xml_parser_new ();
  root = rest_xml_parser_parse_from_data (parser,
                                          rest_proxy_call_get_payload (call),
                                          rest_proxy_call_get_payload_length (call));
  g_object_unref (parser);
  g_object_unref (call);
  g_object_unref (proxy);

  node = rest_xml_node_find (root, "location");
  node = rest_xml_node_find (node, "name");
  g_print ("%s\n", node->content);

  return 0;
}