/// <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); }
/// <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; }
public virtual OAuth2AccessToken GetAccessToken(String code) { var cm = this.CreateGetAccessTokenCommand(code); var text = this.GetBodyText(cm); var t = OAuth2AccessToken.Create(text); return(t); }
public void GetAccessToken(String code, Action <OAuth2AccessToken> callback) { var cm = this.CreateGetAccessTokenCommand(code); this.GetBodyText(cm, text => { var t = OAuth2AccessToken.Create(text); callback(t); }); }
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); }
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)); } }); }
/// <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; }