IExternalAuthenticationSource.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Threading.Tasks;
  2. using IwbZero.MultiTenancy;
  3. namespace IwbZero.Authorization.Base.Users
  4. {
  5. /// <summary>
  6. /// 定义外部授权源
  7. /// </summary>
  8. /// <typeparam name="TTenant">Tenant type</typeparam>
  9. /// <typeparam name="TUser">User type</typeparam>
  10. public interface IExternalAuthenticationSource<TTenant, TUser>
  11. where TTenant : IwbTenant<TUser>
  12. where TUser : UserBase
  13. {
  14. /// <summary>
  15. /// 唯一的认证源名称.
  16. /// This source name is set to <see cref="UserBase.AuthenticationSource"/>
  17. /// 如果用户通过此认证源认证
  18. /// </summary>
  19. string Name { get; }
  20. /// <summary>
  21. /// 用于尝试通过此源对用户进行身份验证
  22. /// </summary>
  23. /// <param name="userNameOrEmailAddress">User name or email address</param>
  24. /// <param name="plainPassword">用户的普通密码</param>
  25. /// <param name="tenant">Tenant of the user or null (if user is a host user)</param>
  26. /// <returns>True, indicates that this used has authenticated by this source</returns>
  27. Task<bool> TryAuthenticateAsync(string userNameOrEmailAddress, string plainPassword, TTenant tenant);
  28. /// <summary>
  29. /// 此方法是由该源验证的用户,但该源尚不存在,因此源应创建用户和填充属性。
  30. /// </summary>
  31. /// <param name="userNameOrEmailAddress">User name or email address</param>
  32. /// <param name="tenant">Tenant of the user or null (if user is a host user)</param>
  33. /// <returns>Newly created user</returns>
  34. Task<TUser> CreateUserAsync(string userNameOrEmailAddress, TTenant tenant);
  35. /// <summary>
  36. /// 此方法是在现有用户通过此源的身份验证后调用的,它可用于由源更新用户的某些属性。
  37. /// </summary>
  38. /// <param name="user">The user that can be updated</param>
  39. /// <param name="tenant">Tenant of the user or null (if user is a host user)</param>
  40. Task UpdateUserAsync(TUser user, TTenant tenant);
  41. }
  42. }