Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OAuthBase"/> class.
        /// </summary>
        /// <param name="authorizeUrl">The address for login.</param>
        /// <param name="accessTokenUrl">The address for the access token.</param>
        /// <param name="applicationId">The application identifier obtained from the provider website.</param>
        /// <param name="applicationSecret">The application secret key obtained from the provider website.</param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="authorizeUrl"/> is <b>null</b> or <b>empty</b>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="accessTokenUrl"/> is <b>null</b> or <b>empty</b>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="applicationId"/> is <b>null</b> or <b>empty</b>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="applicationSecret"/> is <b>null</b> or <b>empty</b>.</para>
        /// </exception>
        public OAuthBase(string authorizeUrl, string accessTokenUrl, string applicationId, string applicationSecret)
        {
            if (String.IsNullOrEmpty(authorizeUrl))
            {
                throw new ArgumentNullException("authorizeUrl");
            }
            if (String.IsNullOrEmpty(accessTokenUrl))
            {
                throw new ArgumentNullException("accessTokenUrl");
            }
            if (String.IsNullOrEmpty(applicationId))
            {
                throw new ArgumentNullException("applicationId");
            }
            if (String.IsNullOrEmpty(applicationSecret))
            {
                throw new ArgumentNullException("applicationSecret");
            }

            this.AuthorizeUrl      = authorizeUrl;
            this.AccessTokenUrl    = accessTokenUrl;
            this.ApplicationId     = applicationId;
            this.ApplicationSecret = applicationSecret;

            // set unique identifier to the instance
            this.State = OAuthUtility.GetRandomKey();
            // add the instance to the clients collection
            OAuthManager.AddRequet(this.State, this);
        }
Exemple #2
0
        /// <summary>
        /// Gets the access token from the remote server.
        /// </summary>
        protected override void GetAccessToken()
        {
            base.GetAccessToken();

            this.Authorization.Parameters.Remove("oauth_signature");

            this.Authorization["oauth_nonce"]     = OAuthUtility.GetRandomKey();
            this.Authorization["oauth_timestamp"] = OAuthUtility.GetTimeStamp();
            this.Authorization["oauth_verifier"]  = this.AuthorizationCode;
            this.Authorization["oauth_token"]     = this.RequestToken.OAuthToken;
            this.Authorization.SetSignature
            (
                "POST",
                new Uri(this.AccessTokenUrl),
                this.ApplicationSecret,
                this.Authorization["oauth_token"].ToString(),
                null
            );

            base.AccessToken = new OAuthAccessToken
                               (
                OAuthUtility.ExecuteRequest
                (
                    "POST",
                    this.AccessTokenUrl,
                    null,
                    this.Authorization.ToString()
                )
                               );

            this.Authorization.Parameters.Remove("oauth_verifier");
        }
 private void DefaultInit()
 {
     this.SignatureMethod = SignatureMethods.HMACSHA1;
     this.Timestamp       = OAuthUtility.GetTimeStamp();
     this.Nonce           = OAuthUtility.GetRandomKey();
     this.Version         = "1.0";
 }
Exemple #4
0
        /// <summary>
        /// Creates a shallow copy of the current object.
        /// </summary>
        /// <returns>A shallow copy of the current object.</returns>
        /// <remarks>
        /// <para>Method creates a copy of the current object, removes tokens, change the return address, query parameters and state.</para>
        /// <para>Unfortunately, I made a mistake in architecture, so I had to make this method.</para>
        /// </remarks>
        /// <seealso cref="Clone(NameValueCollection, string)"/>
        public object Clone()
        {
            OAuthBase result = this.MemberwiseClone() as OAuthBase;

            result.State             = OAuthUtility.GetRandomKey();
            result.AccessToken       = null;
            result.AuthorizationCode = null;

            if (result.GetType().IsSubclassOf(typeof(OAuthClient)))
            {
                ((OAuthClient)result).RequestToken = null;
            }

            OAuthManager.AddRequet(result.State, result);

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OAuthClient"/> class.
        /// </summary>
        /// <param name="requestTokenUrl">The address for the request token.</param>
        /// <param name="authorizeUrl">The address for login.</param>
        /// <param name="accessTokenUrl">The address for the access token.</param>
        /// <param name="consumerKey">The application identifier.</param>
        /// <param name="consumerSecret">The application secret key.</param>
        /// <param name="signatureMethod">The name of hashing algorithm to calculate the signature: HMAC-SHA1 (default) or PLAINTEXT.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="requestTokenUrl"/> is null or empty.</exception>
        public OAuthClient(string requestTokenUrl, string authorizeUrl, string accessTokenUrl, string consumerKey, string consumerSecret, string signatureMethod = SignatureMethods.HMACSHA1) : base(authorizeUrl, accessTokenUrl, consumerKey, consumerSecret)
        {
            if (String.IsNullOrEmpty(requestTokenUrl))
            {
                throw new ArgumentNullException("requestTokenUrl");
            }

            this.RequestTokenUrl = requestTokenUrl;

            this.Authorization["oauth_consumer_key"]     = consumerKey;
            this.Authorization["oauth_nonce"]            = OAuthUtility.GetRandomKey();
            this.Authorization["oauth_signature"]        = "";
            this.Authorization["oauth_signature_method"] = signatureMethod;
            this.Authorization["oauth_timestamp"]        = OAuthUtility.GetTimeStamp();
            this.Authorization["oauth_token"]            = "";
            this.Authorization["oauth_version"]          = "1.0";
        }
Exemple #6
0
        /// <summary>
        /// Creates a shallow copy of the current object.
        /// </summary>
        /// <returns>A shallow copy of the current object.</returns>
        /// <remarks>
        /// <para>Method creates a copy of the current object, removes tokens, change the return address, query parameters and state.</para>
        /// <para>Unfortunately, I made a mistake in architecture, so I had to make this method.</para>
        /// </remarks>
        /// <seealso cref="Clone(NameValueCollection, string)"/>
        public object Clone()
        {
            OAuthBase result = this.MemberwiseClone() as OAuthBase;

            result.State             = OAuthUtility.GetRandomKey();
            result.AccessToken       = null;
            result.AuthorizationCode = null;

            if (result.GetType().IsSubclassOf(typeof(OAuthClient)))
            {
                ((OAuthClient)result).RequestToken = null;
            }

            // I do not remember, why. I'll try to change it. // v1.8
            // OAuthManager.AddRequest(result.State, result.ProviderName, result);
            // --

            return(result);
        }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OAuthBase"/> class.
        /// </summary>
        /// <param name="authorizeUrl">The address for login.</param>
        /// <param name="accessTokenUrl">The address for the access token.</param>
        /// <param name="applicationId">The application identifier obtained from the provider website.</param>
        /// <param name="applicationSecret">The application secret key obtained from the provider website.</param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="authorizeUrl"/> is <b>null</b> or <b>empty</b>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="accessTokenUrl"/> is <b>null</b> or <b>empty</b>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="applicationId"/> is <b>null</b> or <b>empty</b>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="applicationSecret"/> is <b>null</b> or <b>empty</b>.</para>
        /// </exception>
        public OAuthBase(string authorizeUrl, string accessTokenUrl, string applicationId, string applicationSecret)
        {
            if (String.IsNullOrEmpty(authorizeUrl))
            {
                throw new ArgumentNullException("authorizeUrl");
            }
            if (String.IsNullOrEmpty(accessTokenUrl))
            {
                throw new ArgumentNullException("accessTokenUrl");
            }
            if (String.IsNullOrEmpty(applicationId))
            {
                throw new ArgumentNullException("applicationId");
            }
            if (String.IsNullOrEmpty(applicationSecret))
            {
                throw new ArgumentNullException("applicationSecret");
            }

            this.AuthorizeUrl      = authorizeUrl;
            this.AccessTokenUrl    = accessTokenUrl;
            this.ApplicationId     = applicationId;
            this.ApplicationSecret = applicationSecret;

            // set unique identifier to the instance
            this.State = OAuthUtility.GetRandomKey();

            // default values
            this.SupportRefreshToken = false;
            this.SupportRevokeToken  = false;

            // I do not remember, why. I'll try to change it. // v1.8
            // add the instance to the clients collection
            // OAuthManager.AddRequest(this.State, this.ProviderName, this);
            // --
        }
 /// <summary>
 /// Updates the nonce and the timestamp.
 /// </summary>
 internal void UpdateStamp()
 {
     this.Nonce     = OAuthUtility.GetRandomKey();
     this.Timestamp = OAuthUtility.GetTimeStamp();
 }
Exemple #9
0
 /// <summary>
 /// Updates the nonce and timestamp.
 /// </summary>
 private void UpdateStamp()
 {
     this.Authorization["oauth_nonce"]     = OAuthUtility.GetRandomKey();
     this.Authorization["oauth_timestamp"] = OAuthUtility.GetTimeStamp();
 }