private async Task GetTokenAsync(AzureAccount az) { try { Match lnk = _emailRgx.Match(az.User); az.User = lnk.Success ? lnk.Value : ""; if (!az.PasswordSet) { throw new ApplicationException(Resources.ProvideAccountPassword); } az.UpdatePassword(db); TokenInfo ti = await Token.GetGrantTypePasswordAsync( az.Resource, az.ClientId, az.ClientSecret, az.User, Setting.GetEncryptor(db).Decrypt(az.Password), az.TenantId ); az.RefreshToken = ti.RefreshToken; az.AccessToken = ti.AccessToken; az.ExpiresOn = ti.ExpiresOn; az.IdToken = ti.IdToken; db.Entry(az).State = EntityState.Modified; //var errors = ModelState.Values.SelectMany(v => v.Errors).ToArray(); } catch (AzureTokenException ex) { ModelState.AddModelError("User", ex.Details); } catch (ApplicationException ex) { ModelState.AddModelError("PasswordUnmasked", ex.Message); } }