示例#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
            });
        }
示例#2
0
 private static string CreateUserDataUri(string accessToken)
 {
     return(OAuthHelpers.BuildUri(ApiUrl, "v1/people/~", new NameValueCollection {
         { "oauth2_access_token", accessToken },
         { "format", "json" }
     }));
 }
示例#3
0
        private static string CreateUserInfoUri(string userId)
        {
            var param = new NameValueCollection {
                { "uids", userId }
            };

            return(OAuthHelpers.BuildUri(ApiUrl, OAuthGetUsersPath, param));
        }
示例#4
0
        private static string CreateRedirectUrl(string requestToken)
        {
            var parameters = new NameValueCollection {
                { "oauth_token", requestToken }
            };

            return(OAuthHelpers.BuildUri(OAuthUrl, OAuthAuthenticatePath, parameters));
        }
示例#5
0
 public static string CreateRedirectionUri(string url, string path, string appId, Uri returnUrl)
 {
     return(OAuthHelpers.BuildUri(url, path, new NameValueCollection {
         { "client_id", appId },
         { "redirect_uri", HttpUtility.UrlEncode(returnUrl.AbsoluteUri) },
         { "response_type", "code" },
     }));
 }
示例#6
0
 private string CreateAccessTokenUrl(string authorizationCode, Uri returnUrl)
 {
     return(OAuthHelpers.BuildUri(ApiUrl, "oauth/access_token", new NameValueCollection {
         { "client_id", AppId },
         { "client_secret", _appSecret },
         { "redirect_uri", HttpUtility.UrlEncode(returnUrl.AbsoluteUri) },
         { "code", authorizationCode },
     }));
 }
示例#7
0
 private string CreateAccessTokenUri(HttpContextBase context)
 {
     return(OAuthHelpers.BuildUri(OAuthUrl, OAuthAccessTokenPath, new NameValueCollection {
         { "grant_type", "authorization_code" },
         { "code", context.Request["code"] },
         { "redirect_uri", _redirectUri },
         { "client_id", _appKey },
         { "client_secret", _appSecret }
     }));
 }
示例#8
0
 private string CreateRedirectUri(Uri returnUrl)
 {
     return(OAuthHelpers.BuildUri(OAuthUrl, "o/oauth2/auth", new NameValueCollection
     {
         { "client_id", _appId },
         { "redirect_uri", returnUrl.GetLeftPart(UriPartial.Path) },
         { "response_type", "code" },
         { "scope", "profile" },
         { "state", HttpUtility.UrlEncode(returnUrl.Query) }
     }));
 }
示例#9
0
        private string CreateBuildUri(string code)
        {
            var param = new NameValueCollection {
                { "client_id", _appId },
                { "client_secret", _appSecret },
                { "code", code },
                { "redirect_uri", _redirectUri }
            };

            return(OAuthHelpers.BuildUri(OAuthUrl, OAuthTokenPath, param));
        }
示例#10
0
        private string CreateRedirectionUri()
        {
            var param = new NameValueCollection {
                { "response_type", "code" },
                { "client_id", _appKey },
                { "state", Guid.NewGuid().ToString("N") },
                { "redirect_uri", _redirectUri }
            };

            return(OAuthHelpers.BuildUri(OAuthUrl, OAuthAuthorizationPath, param));
        }
示例#11
0
        private string GetAccessToken(string authorizationCode, Uri returnUrl)
        {
            var param = new NameValueCollection {
                { "client_id", _appId },
                { "client_secret", _appSecret },
                { "code", authorizationCode },
                { "grant_type", "authorization_code" },
                { "redirect_uri", returnUrl.GetLeftPart(UriPartial.Path) },
            };
            var url = OAuthHelpers.BuildUri(OAuthUrl, "o/oauth2/token", new NameValueCollection());

            return(OAuthHelpers.GetObjectWithPost(url, param).access_token);
        }
        public void RequestAuthentication(HttpContextBase context, Uri returnUrl)
        {
            var requestTokenUrl = CreateRequestTokenUrl(returnUrl);
            var response        = OAuthHelpers.Load(requestTokenUrl);

            RegenerateSignatureKey(response);

            var url = OAuthHelpers.BuildUri(FlickrUrl, "services/oauth/authorize", new NameValueCollection {
                { "oauth_token", HttpUtility.ParseQueryString(response).Get("oauth_token") }
            });

            context.Response.Redirect(url, false);
        }
示例#13
0
        private static UserInfo GetUserData(string accessToken)
        {
            var uri = OAuthHelpers.BuildUri(ApiUrl, "oauth2/v1/userinfo", new NameValueCollection {
                { "access_token", accessToken }
            });

            var response = OAuthHelpers.GetObjectFromAddress(uri);

            return(new UserInfo {
                Id = response.id,
                UserName = response.name
            });
        }
示例#14
0
        public void RequestAuthentication(HttpContextBase context, Uri returnUrl)
        {
            var requestTokenUrl = CreateRequestTokenUrl(returnUrl);
            var response        = OAuthHelpers.Load(requestTokenUrl);

            RegenerateSignatureKey(response);

            var url = OAuthHelpers.BuildUri(TumblrUrl, "oauth/authorize", new NameValueCollection {
                { "oauth_token", OAuthHelpers.GetValueFromRequest(response, "oauth_token") }
            });

            context.Response.Redirect(url, false);
        }
示例#15
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));
        }
        private UserInfo GetAccessInfo(string code)
        {
            var param = new NameValueCollection {
                { "client_id", _clientId },
                { "client_secret", _clientSecret },
                { "code", code },
                { "grant_type", "authorization_code" },
                { "redirect_uri", _redirectUri }
            };

            var url      = OAuthHelpers.BuildUri(OAuthUrl, OauthAccessTokenPath, new NameValueCollection());
            var response = OAuthHelpers.GetObjectWithPost(url, param);

            return(new UserInfo {
                Id = response.user.id,
                UserName = response.user.full_name
            });
        }
示例#17
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));
        }
示例#18
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));
        }
示例#19
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));
        }
示例#20
0
 private static string CreateUserInfoUri(string accessToken)
 {
     return(OAuthHelpers.BuildUri(ApiUrl, "me", new NameValueCollection {
         { "access_token", accessToken }
     }));
 }