Exemple #1
0
        private void btnRequestTemporaryCredentials_Click(object sender, EventArgs e)
        {
            try
            {
                oauth = new OAuthProcess(
                    new ClientCredentials(txtClientIdentifier.Text.Trim(), txtClientSharedSecret.Text.Trim()),
                    txtRequestTokenUrl.Text.Trim(),
                    txtAuthorizeUrl.Text.Trim(),
                    txtAccessTokenUrl.Text.Trim());
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occured while creating an OAuth object. you must provide valid informations!", "Error");
            }

            try
            {
                oauth.RequestTemporaryCredentials(txtCallbackUrl.Text.Trim());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "An error occured while requesting temporary credentials!");
            }

            try
            {
                txtAuthorizationRequestUrl.Text = oauth.GetAuthorizationUri();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occured while requesting the authorization uri!\n" + ex.ToString(), "Error");
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //application already authorized
            var    oauth   = new OAuthClient(new ClientCredentials(consumerKey, secretKey), new TokenCredentials(tokenIdentifier, tokenSharedSecret));
            var    request = oauth.CreateAuthenticatedRequest("http://api.tumblr.com/v2/user/info");
            string x;

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                using (var sr = new System.IO.StreamReader(response.GetResponseStream()))
                {
                    x = sr.ReadToEnd();
                }
            }

            //full authorization process
            var oauthProcess = new OAuthProcess(new ClientCredentials(consumerKey, secretKey),
                                                "http://www.tumblr.com/oauth/request_token",
                                                "http://www.tumblr.com/oauth/authorize",
                                                "http://www.tumblr.com/oauth/access_token");

            oauthProcess.RequestTemporaryCredentials();
            var authorizationRequestUri = oauthProcess.GetAuthorizationUri();
            //the user must visit the authorization uri and accept the application to continue.
            //they are then redirected to the callback uri, with the required oauth parameters provided by the server.
            string verifier = oauthProcess.ParseVerifierFromAuthorizedCallbackUri("http://authorizedCallbackUri");
            //alternatively, if the server directly provides a verifier (i.e twitter pin) to the user, it can be used here.
            var tokenCredentials = oauthProcess.RequestTokenCredentials(verifier);

            oauth = new OAuthClient(oauthProcess.ClientCredentials, tokenCredentials);

            request = (HttpWebRequest)HttpWebRequest.Create("http://api.tumblr.com/v2/user/info");
            oauth.MakeRequestAuthenticated(request);
            string y;

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                using (var sr = new System.IO.StreamReader(response.GetResponseStream()))
                {
                    y = sr.ReadToEnd();
                }
            }
        }