|
1 |
| -using System.Threading.Tasks; |
2 |
| - |
3 |
| -using GenHTTP.Api.Content.Authentication; |
4 |
| -using GenHTTP.Api.Protocol; |
5 |
| - |
6 |
| -namespace GenHTTP.Modules.Authentication.Web |
7 |
| -{ |
8 |
| - |
9 |
| - public interface ISimpleWebAuthIntegration |
10 |
| - { |
11 |
| - |
12 |
| - bool AllowAnonymous { get => false; } |
13 |
| - |
14 |
| - string SetupRoute { get => "setup"; } |
15 |
| - |
16 |
| - string LoginRoute { get => "login"; } |
17 |
| - |
18 |
| - string LogoutRoute { get => "logout"; } |
19 |
| - |
20 |
| - string ResourceRoute { get => "auth-resources"; } |
21 |
| - |
22 |
| - ValueTask<bool> CheckSetupRequired(IRequest request); |
23 |
| - |
24 |
| - ValueTask PerformSetup(IRequest request, string username, string password); |
25 |
| - |
26 |
| - ValueTask<IUser?> VerifyTokenAsync(string sessionToken); |
27 |
| - |
28 |
| - ValueTask<string> StartSessionAsync(IRequest request, IUser user); |
29 |
| - |
30 |
| - ValueTask<IUser?> PerformLogin(IRequest request, string username, string password); |
31 |
| - |
32 |
| - } |
33 |
| - |
34 |
| -} |
| 1 | +using System.Threading.Tasks; |
| 2 | + |
| 3 | +using GenHTTP.Api.Content.Authentication; |
| 4 | +using GenHTTP.Api.Protocol; |
| 5 | + |
| 6 | +namespace GenHTTP.Modules.Authentication.Web |
| 7 | +{ |
| 8 | + |
| 9 | + /// <summary> |
| 10 | + /// Authentication and authorization logic to be used by the |
| 11 | + /// web authentication concern. |
| 12 | + /// </summary> |
| 13 | + /// <typeparam name="TUser">The type of user managed by this integration</typeparam> |
| 14 | + /// <remarks> |
| 15 | + /// Use this kind of integration if you would like to quickly |
| 16 | + /// add login forms to your application. This integration will |
| 17 | + /// use a default set of controllers that render very simple |
| 18 | + /// UIs to you app users. |
| 19 | + /// |
| 20 | + /// If you would like to customize the authentication workflow, |
| 21 | + /// use <see cref="IWebAuthIntegration{TUser}" /> instead. |
| 22 | + /// </remarks> |
| 23 | + public interface ISimpleWebAuthIntegration<TUser> where TUser : IUser |
| 24 | + { |
| 25 | + |
| 26 | + /// <summary> |
| 27 | + /// False if you would like to force non logged in users |
| 28 | + /// to log in. |
| 29 | + /// </summary> |
| 30 | + bool AllowAnonymous { get => false; } |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// The route the setup functionality will be available |
| 34 | + /// from (defaults to "/setup/"). |
| 35 | + /// </summary> |
| 36 | + string SetupRoute { get => "setup"; } |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// The route the login page will be available from |
| 40 | + /// (defaults to "/login/"). |
| 41 | + /// </summary> |
| 42 | + string LoginRoute { get => "login"; } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// The route the logout page will be available from |
| 46 | + /// (defaults to "/logout/"). |
| 47 | + /// </summary> |
| 48 | + string LogoutRoute { get => "logout"; } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// The route used to serve additional resources required |
| 52 | + /// by the default controllers. |
| 53 | + /// </summary> |
| 54 | + /// <remarks> |
| 55 | + /// This is used by the default controllers which implement |
| 56 | + /// the simple integration flow to serve additional style sheets |
| 57 | + /// to style the login page. |
| 58 | + /// </remarks> |
| 59 | + string ResourceRoute { get => "auth-resources"; } |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// Return true to redirect users to a setup page that allows |
| 63 | + /// an administrator setting up your application to initially |
| 64 | + /// create an accont with. |
| 65 | + /// </summary> |
| 66 | + /// <param name="request">The currently handled request</param> |
| 67 | + /// <returns>true if the application needs to be set up</returns> |
| 68 | + /// <remarks> |
| 69 | + /// This feature allows you to provision your application without |
| 70 | + /// the need of using fixed user accounts which would compromise |
| 71 | + /// the security of your deployments. |
| 72 | + /// |
| 73 | + /// Typically you want to return true while there are no users |
| 74 | + /// yet and false as soon as there are some. |
| 75 | + /// |
| 76 | + /// To disable the feature completely, just return false here. |
| 77 | + /// </remarks> |
| 78 | + ValueTask<bool> CheckSetupRequired(IRequest request); |
| 79 | + |
| 80 | + /// <summary> |
| 81 | + /// Called by the setup controller to initialize your application |
| 82 | + /// for the given admin user. |
| 83 | + /// </summary> |
| 84 | + /// <param name="request">The currently handled request</param> |
| 85 | + /// <param name="username">The name entered by the user</param> |
| 86 | + /// <param name="password">The password entered by the user</param> |
| 87 | + /// <remarks> |
| 88 | + /// After this call, <see cref="CheckSetupRequired(IRequest)" /> is |
| 89 | + /// expected to return false on subsequent calls. |
| 90 | + /// </remarks> |
| 91 | + ValueTask PerformSetup(IRequest request, string username, string password); |
| 92 | + |
| 93 | + /// <summary> |
| 94 | + /// Invoked with the session token read from the client connection |
| 95 | + /// to actually load and check the session. |
| 96 | + /// </summary> |
| 97 | + /// <param name="request">The currently handled request</param> |
| 98 | + /// <param name="sessionToken">The token read from the client connection</param> |
| 99 | + /// <returns>The user record the session belongs to or null, if the session is not valid anymore</returns> |
| 100 | + /// <remarks> |
| 101 | + /// In this method you will need to verify the session specified by the client |
| 102 | + /// against some session storage, e.g. a Redis or database server. |
| 103 | + /// </remarks> |
| 104 | + ValueTask<TUser?> VerifyTokenAsync(IRequest request, string sessionToken); |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// Invoked to generate a new session token for the authenticated user. |
| 108 | + /// </summary> |
| 109 | + /// <param name="request">The currently handled request</param> |
| 110 | + /// <param name="user">The user which just performed a login</param> |
| 111 | + /// <returns>The newly created (or re-used) session token</returns> |
| 112 | + ValueTask<string> StartSessionAsync(IRequest request, TUser user); |
| 113 | + |
| 114 | + /// <summary> |
| 115 | + /// Invoked to actually authenticate an user who entered their |
| 116 | + /// credentials in the login form. |
| 117 | + /// </summary> |
| 118 | + /// <param name="request">The currently handled request</param> |
| 119 | + /// <param name="username">The name of the user</param> |
| 120 | + /// <param name="password">The password of the user</param> |
| 121 | + /// <returns>The matching user record if the credentials are valid</returns> |
| 122 | + /// <remarks> |
| 123 | + /// If the user account does not exist or the credentials are incorrect, |
| 124 | + /// return null to cause the controller to render an error message. |
| 125 | + /// </remarks> |
| 126 | + ValueTask<TUser?> PerformLoginAsync(IRequest request, string username, string password); |
| 127 | + |
| 128 | + } |
| 129 | + |
| 130 | +} |
0 commit comments