示例#1
0
 public bool Configuration(string key, object value)
 {
     if (key == "MaxUploadFilesize")
     {
         long val;
         try
         {
             val = Convert.ToInt64(value);
             if (val > 0)
             {
                 this._MaxFileSize = val;
             }
             else
             {
                 this._MaxFileSize = TwitterPhoto.MaxfilesizeDefault;
             }
         }
         catch (Exception)
         {
             this._MaxFileSize = TwitterPhoto.MaxfilesizeDefault;
             return(false);   // error
         }
         return(true);        // 正常に設定終了
     }
     return(true);            // 設定項目がない場合はとりあえずエラー扱いにしない
 }
示例#2
0
        /// <summary>
        /// OAuthで使用する共通情報を取得する
        /// </summary>
        /// <param name="token">アクセストークン、もしくはリクエストトークン。未取得なら空文字列</param>
        /// <returns>OAuth情報のディクショナリ</returns>
        protected Dictionary <string, string> GetOAuthParameter(string token)
        {
            Dictionary <string, string> parameter = new Dictionary <string, string>();

            parameter.Add("oauth_consumer_key", this.consumerKey);
            parameter.Add("oauth_signature_method", "HMAC-SHA1");
            parameter.Add("oauth_timestamp", Convert.ToInt64((DateTime.UtcNow - HttpConnectionOAuth.UnixEpoch).TotalSeconds).ToString());                   // epoch秒
            parameter.Add("oauth_nonce", HttpConnectionOAuth.NonceRandom.Next(123400, 9999999).ToString());
            parameter.Add("oauth_version", "1.0");
            if (!string.IsNullOrEmpty(token))
            {
                parameter.Add("oauth_token", token);                   // トークンがあれば追加
            }
            return(parameter);
        }
示例#3
0
        /// <summary>
        /// OAuth認証のアクセストークン取得。xAuth方式
        /// </summary>
        /// <param name="accessTokenUrl">アクセストークンの取得先URL</param>
        /// <param name="username">認証用ユーザー名</param>
        /// <param name="password">認証用パスワード</param>
        /// <returns>取得結果真偽値</returns>
        public HttpStatusCode AuthenticateXAuth(Uri accessTokenUrl, string username, string password, ref string content)
        {
            // ユーザー・パスワードチェック
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                throw new Exception("Sequence error.(username or password is blank)");
            }

            // xAuthの拡張パラメータ設定
            Dictionary <string, string> parameter = new Dictionary <string, string>();

            parameter.Add("x_auth_mode", "client_auth");
            parameter.Add("x_auth_username", username);
            parameter.Add("x_auth_password", password);

            // アクセストークン取得
            HttpStatusCode httpCode = this.GetOAuthToken(accessTokenUrl, "", "", parameter, ref content);

            if (httpCode != HttpStatusCode.OK)
            {
                return(httpCode);
            }
            NameValueCollection accessTokenData = base.ParseQueryString(content);

            if (accessTokenData != null)
            {
                this.token       = accessTokenData["oauth_token"];
                this.tokenSecret = accessTokenData["oauth_token_secret"];

                // サービスごとの独自拡張対応
                if (!string.IsNullOrEmpty(this.userIdentKey))
                {
                    this.authorizedUsername = accessTokenData[this.userIdentKey];
                }
                else
                {
                    this.authorizedUsername = "";
                }

                if (!string.IsNullOrEmpty(this.userIdIdentKey))
                {
                    try
                    {
                        this.authorizedUserId = Convert.ToInt64(accessTokenData[this.userIdIdentKey]);
                    }
                    catch (Exception)
                    {
                        this.authorizedUserId = 0;
                    }
                }
                else
                {
                    this.authorizedUserId = 0;
                }

                if (string.IsNullOrEmpty(token))
                {
                    throw new InvalidDataException("Token is null.");
                }
                return(HttpStatusCode.OK);
            }
            else
            {
                throw new InvalidDataException("Return value is null.");
            }
        }
示例#4
0
        /// <summary>
        /// OAuth認証のアクセストークン取得。PIN入力用の後段
        /// </summary>
        /// <remarks>
        /// 事前にAuthenticatePinFlowRequestを呼んで、ブラウザで認証後に表示されるPINを入力してもらい、その値とともに呼び出すこと
        /// </remarks>
        /// <param name="accessTokenUrl">アクセストークンの取得先URL</param>
        /// <param name="requestToken">AuthenticatePinFlowRequestで取得したリクエストトークン</param>
        /// <param name="pinCode">Webで認証後に表示されるPINコード</param>
        /// <returns>取得結果真偽値</returns>
        public HttpStatusCode AuthenticatePinFlow(string accessTokenUrl, string requestToken, string pinCode)
        {
            // PIN-based flow
            if (string.IsNullOrEmpty(requestToken))
            {
                throw new Exception("Sequence error.(requestToken is blank)");
            }

            // アクセストークン取得
            string content = "";
            NameValueCollection accessTokenData;
            HttpStatusCode      httpCode = this.GetOAuthToken(new Uri(accessTokenUrl), pinCode, requestToken, null, ref content);

            if (httpCode != HttpStatusCode.OK)
            {
                return(httpCode);
            }
            accessTokenData = base.ParseQueryString(content);

            if (accessTokenData != null)
            {
                this.token       = accessTokenData["oauth_token"];
                this.tokenSecret = accessTokenData["oauth_token_secret"];

                // サービスごとの独自拡張対応
                if (!string.IsNullOrEmpty(this.userIdentKey))
                {
                    this.authorizedUsername = accessTokenData[this.userIdentKey];
                }
                else
                {
                    this.authorizedUsername = "";
                }

                if (!string.IsNullOrEmpty(this.userIdIdentKey))
                {
                    try
                    {
                        this.authorizedUserId = Convert.ToInt64(accessTokenData[this.userIdIdentKey]);
                    }
                    catch (Exception)
                    {
                        this.authorizedUserId = 0;
                    }
                }
                else
                {
                    this.authorizedUserId = 0;
                }

                if (string.IsNullOrEmpty(token))
                {
                    throw new InvalidDataException("Token is null.");
                }
                return(HttpStatusCode.OK);
            }
            else
            {
                throw new InvalidDataException("Return value is null.");
            }
        }