protected void SetToken(string providerName, ApplicationUserToken token) { var curr = this.GetToken(providerName); if (token != null) { token.ProviderName = providerName; if (curr == null) { this.Tokens.Add(token); } else if (curr != token) { if (curr.Id != token.Id) { this.Tokens.Remove(curr); this.Tokens.Add(token); } else { curr.ProviderName = token.ProviderName; curr.ApplicationUserId = token.ApplicationUserId; curr.AccessToken = token.AccessToken; curr.ModifiedDate = token.ModifiedDate; curr.Expires = token.Expires; } } else { } // no change } else { if (curr != null) { this.GetTokens(providerName)?.ToList().ForEach(_ => this.Tokens.Remove(_)); } else { } // no change } }
internal void SetToken(string providerName, string accessToken, string secretToken = null, DateTime?expires = null) { ApplicationUserToken token = this.GetToken(providerName); if (token == null) { token = new ApplicationUserToken() { ProviderName = providerName, }; } // //token.ProviderName = providerName; token.ApplicationUserId = this.Id; token.AccessToken = accessToken; token.SecretToken = secretToken; token.Expires = expires; token.ModifiedDate = DateTime.UtcNow; // this.SetToken(providerName, token); }