public OAuthTokenDetails RefreshToken()
        {
            if (AuthDetails == null ||
                !(AuthDetails is OAuthAuthenticationDetails) ||
                string.IsNullOrEmpty(
                    (AuthDetails as OAuthAuthenticationDetails)
                    .RefreshToken))
            {
                throw new InvalidOperationException(
                          "You cannot refresh an OAuth token when you don't have a refresh token.");
            }

            string refreshToken = (this.AuthDetails as OAuthAuthenticationDetails)
                                  .RefreshToken;
            string body = string.Format(
                "grant_type=refresh_token&refresh_token={0}",
                Uri.EscapeDataString(refreshToken));

            OAuthTokenDetails newTokenDetails =
                HttpHelper.Post <string, OAuthTokenDetails, OAuthErrorResult>(
                    null, "/token", new NameValueCollection(), body,
                    options.BaseOAuthUri,
                    HttpHelper.APPLICATION_FORM_URLENCODED_CONTENT_TYPE);

            Authenticate(
                new OAuthAuthenticationDetails(
                    newTokenDetails.access_token, newTokenDetails.refresh_token));
            return(newTokenDetails);
        }
示例#2
0
        public OAuthTokenDetails RefreshToken()
        {
            if (AuthDetails == null ||
                !(AuthDetails is OAuthAuthenticationDetails) ||
                string.IsNullOrEmpty(
                    (AuthDetails as OAuthAuthenticationDetails)
                    .RefreshToken))
            {
                throw new InvalidOperationException(
                          "You cannot refresh an OAuth token when you don't have a refresh token.");
            }

            string refreshToken = (this.AuthDetails as OAuthAuthenticationDetails)
                                  .RefreshToken;

            var values = new Dictionary <string, string>();

            values.Add("grant_type", "refresh_token");
            values.Add("refresh_token", refreshToken);
            string body = QueryHelpers.AddQueryString("", values);

            OAuthTokenDetails newTokenDetails =
                HttpHelper.Post <string, OAuthTokenDetails, OAuthErrorResult>(
                    null, "/token", new NameValueCollection(), body,
                    options.BaseOAuthUri,
                    HttpHelper.APPLICATION_FORM_URLENCODED_CONTENT_TYPE);

            Authenticate(
                new OAuthAuthenticationDetails(
                    newTokenDetails.access_token, newTokenDetails.refresh_token));
            return(newTokenDetails);
        }