Exemplo n.º 1
0
        private UserInfo GetUserData(string token)
        {
            var parameters = new NameValueCollection {
                { "oauth_consumer_key", _appId },
                { "oauth_nonce", SignatureGenerator.GenerateNonce() },
                { "oauth_signature_method", SignatureMethod },
                { "oauth_timestamp", SignatureGenerator.GetTimestamp() },
                { "oauth_token", token },
                { "oauth_version", "1.0" },
            };
            var parametersString = OAuthHelpers.ConstructQueryString(parameters);

            var signature = _signatureGenerator.GenerateSignature("GET", TumblrApi + "v2/user/info", parametersString);

            parameters.Set("oauth_signature", signature);

            var auth = "OAuth" + OAuthHelpers.ConstructQueryString(parameters, ",");

            var userInfoUrl = OAuthHelpers.BuildUri(TumblrApi, "v2/user/info", parameters);
            var response    = OAuthHelpers.AuthorizationLoad(userInfoUrl, auth);

            dynamic obj = JObject.Parse(response);

            return(new UserInfo {
                Id = obj.response.user.blogs[0].url,
                UserName = obj.response.user.name
            });
        }
Exemplo n.º 2
0
        public void RequestAuthentication(HttpContextBase context, Uri returnUrl)
        {
            _redirectUri = returnUrl.AbsoluteUri;

            var url          = CreateRequestTokenUrl();
            var request      = OAuthHelpers.Load(url);
            var requestToken = OAuthHelpers.GetValueFromRequest(request, "oauth_token");

            _tokenSecret        = OAuthHelpers.GetValueFromRequest(request, "oauth_token_secret");
            _signatureGenerator = new SignatureGenerator(_appSecret, _tokenSecret);

            var redirectUrl = CreateRedirectUrl(requestToken);

            context.Response.Redirect(redirectUrl, false);
        }
Exemplo n.º 3
0
        private string CreateRequestTokenUrl()
        {
            var parameters = new NameValueCollection {
                { "oauth_callback", SignatureGenerator.Encode(_redirectUri) },
                { "oauth_consumer_key", _appId },
                { "oauth_nonce", SignatureGenerator.GenerateNonce() },
                { "oauth_signature_method", SignatureMethod },
                { "oauth_timestamp", SignatureGenerator.GetTimestamp() },
                { "oauth_version", OAuthValue }
            };

            var parametersString = OAuthHelpers.ConstructQueryString(parameters);
            var signature        = _signatureGenerator.GenerateSignature("GET", OAuthUrl + OAuthRequestTokenPath, parametersString, true);

            parameters.Set("oauth_signature", signature);

            return(OAuthHelpers.BuildUri(OAuthUrl, OAuthRequestTokenPath, parameters));
        }
Exemplo n.º 4
0
        private string CreateRequestTokenUrl(Uri returnUrl)
        {
            var parameters = new NameValueCollection {
                { "oauth_callback", SignatureGenerator.Encode(returnUrl.AbsoluteUri) },
                { "oauth_consumer_key", _appId },
                { "oauth_nonce", SignatureGenerator.GenerateNonce() },
                { "oauth_signature_method", SignatureMethod },
                { "oauth_timestamp", SignatureGenerator.GetTimestamp() },
                { "oauth_version", "1.0" },
            };
            var parametersString = OAuthHelpers.ConstructQueryString(parameters);

            var signature = _signatureGenerator.GenerateSignature("GET", TumblrUrl + "oauth/request_token", parametersString, true);

            parameters.Set("oauth_signature", signature);

            return(OAuthHelpers.BuildUri(TumblrUrl, "oauth/request_token", parameters));
        }
Exemplo n.º 5
0
        private string CreateUserInfoUrl(HttpContextBase context)
        {
            var parameters = new NameValueCollection {
                { "oauth_consumer_key", _appId },
                { "oauth_nonce", SignatureGenerator.GenerateNonce() },
                { "oauth_signature_method", SignatureMethod },
                { "oauth_timestamp", SignatureGenerator.GetTimestamp() },
                { "oauth_token", context.Request.QueryString["oauth_token"] },
                { "oauth_verifier", context.Request.QueryString["oauth_verifier"] },
                { "oauth_version", OAuthValue }
            };

            var parametersString = OAuthHelpers.ConstructQueryString(parameters);
            var signature        = _signatureGenerator.GenerateSignature("GET", OAuthUrl + OAuthAccessTokenPath, parametersString);

            parameters.Set("oauth_signature", signature);

            return(OAuthHelpers.BuildUri(OAuthUrl, OAuthAccessTokenPath, parameters));
        }
Exemplo n.º 6
0
        private string CreateAccessTokenUrl(HttpContextBase context)
        {
            var parameters = new NameValueCollection {
                { "oauth_consumer_key", _appId },
                { "oauth_nonce", SignatureGenerator.GenerateNonce() },
                { "oauth_signature_method", "HMAC-SHA1" },
                { "oauth_timestamp", SignatureGenerator.GetTimestamp() },
                { "oauth_token", context.Request["oauth_token"] },
                { "oauth_verifier", context.Request["oauth_verifier"] },
                { "oauth_version", "1.0" },
            };
            var parametersString = OAuthHelpers.ConstructQueryString(parameters);

            var signature = _signatureGenerator.GenerateSignature("GET", TumblrUrl + "oauth/access_token", parametersString);

            parameters.Set("oauth_signature", signature);

            return(OAuthHelpers.BuildUri(TumblrUrl, "oauth/access_token", parameters));
        }
 private void RegenerateSignatureKey(string response)
 {
     _tokenSecret        = HttpUtility.ParseQueryString(response).Get("oauth_token_secret");
     _signatureGenerator = new SignatureGenerator(_appSecret, _tokenSecret);
 }
 public FlickrOAuthClient(string appId, string appSecret)
 {
     _appId              = appId;
     _appSecret          = appSecret;
     _signatureGenerator = new SignatureGenerator(_appSecret, _tokenSecret);
 }