コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        public static OAuth2AccessToken Create(String jsonText)
        {
            OAuth2AccessToken t = new OAuth2AccessToken();

            t.JsonText = jsonText;
            var d = AppEnvironment.Settings.JsonSerializer.Deserialize <Dictionary <String, String> >(jsonText);

            foreach (var key in d.Keys)
            {
                t.Values[key] = d[key].ToString();
            }
            t.Value        = d.GetValueOrDefault("access_token");
            t.ExpiresIn    = d.GetValueOrDefault("expired_in").ToInt32() ?? 0;
            t.TokenType    = d.GetValueOrDefault("token_type");
            t.RefreshToken = d.GetValueOrDefault("refresh_token");

            if (String.IsNullOrEmpty(t.Value) == true)
            {
                t.State = OAuthAccessTokenState.Error;
            }
            else
            {
                t.State = OAuthAccessTokenState.Success;
            }

            return(t);
        }
コード例 #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="accessToken"></param>
 public void SetProperty(OAuth2AccessToken accessToken)
 {
     this.Value        = accessToken.Value;
     this.ExpiresIn    = accessToken.ExpiresIn;
     this.TokenType    = accessToken.TokenType;
     this.RefreshToken = accessToken.RefreshToken;
 }
コード例 #3
0
        public virtual OAuth2AccessToken GetAccessToken(String code)
        {
            var cm   = this.CreateGetAccessTokenCommand(code);
            var text = this.GetBodyText(cm);
            var t    = OAuth2AccessToken.Create(text);

            return(t);
        }
コード例 #4
0
        public void GetAccessToken(String code, Action <OAuth2AccessToken> callback)
        {
            var cm = this.CreateGetAccessTokenCommand(code);

            this.GetBodyText(cm, text =>
            {
                var t = OAuth2AccessToken.Create(text);
                callback(t);
            });
        }
コード例 #5
0
ファイル: OAuth2Client.Async.cs プロジェクト: youye00/higlabo
        public Task <OAuth2AccessToken> GetAccessTokenAsync(String code)
        {
            var result = new TaskCompletionSource <OAuth2AccessToken>();
            var cm     = this.CreateGetAccessTokenCommand(code);

            this.GetBodyText(cm, text =>
            {
                var token = OAuth2AccessToken.Create(text);
                result.SetResult(token);
            });
            return(result.Task);
        }
コード例 #6
0
 public void Authenticate(String code, Action callback)
 {
     this.GetAccessToken(code, token =>
     {
         this.AccessToken = token;
         if (this.AccessToken.State == OAuthAccessTokenState.Success)
         {
             callback();
         }
         else
         {
             var ex = new OAuthAuthenticateException(token.JsonText, "");
             this.OnError(new AsyncHttpCallErrorEventArgs(null, ex));
         }
     });
 }
コード例 #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        /// <returns></returns>
        public static OAuth2AccessToken Create(String jsonText)
        {
            OAuth2AccessToken t = new OAuth2AccessToken();
            t.JsonText = jsonText;
            var d = AppEnvironment.Settings.JsonSerializer.Deserialize<Dictionary<String, String>>(jsonText);
            foreach (var key in d.Keys)
            {
                t.Values[key] = d[key].ToString();
            }
            t.Value = d.GetValueOrDefault("access_token");
            t.ExpiresIn = d.GetValueOrDefault("expired_in").ToInt32() ?? 0;
            t.TokenType = d.GetValueOrDefault("token_type");
            t.RefreshToken = d.GetValueOrDefault("refresh_token");

            if (String.IsNullOrEmpty(t.Value) == true)
            {
                t.State = OAuthAccessTokenState.Error;
            }
            else
            {
                t.State = OAuthAccessTokenState.Success;
            }

            return t;
        }
コード例 #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="accessToken"></param>
 public void SetProperty(OAuth2AccessToken accessToken)
 {
     this.Value = accessToken.Value;
     this.ExpiresIn = accessToken.ExpiresIn;
     this.TokenType = accessToken.TokenType;
     this.RefreshToken = accessToken.RefreshToken;
 }