Authentication Schemes and Options Pattern Implementation
Closed this issue · 4 comments
Authentication Scheme Requirements:
-
Create a new ASP.NET Core web application.
-
Configure the authentication schemes in the
Startup.cs
file, specifying Cookie Authentication as the default scheme. -
Implement different endpoints in a controller. Do not specify endpoint names in this task:
- The first endpoint should be authenticated using Cookie Authentication.
- The second endpoint should be authenticated using JWT Authentication if the request header contains a Bearer token.
- For certain endpoints, restrict the authentication method explicitly. For example, one endpoint should only allow Cookie Authentication, while another should only allow JWT Authentication.
-
Ensure that the authentication middleware and services are properly configured to handle both cookies and JWT tokens.
-
Demonstrate the ability to access user data or roles based on the authentication scheme used for each endpoint.
-
Test the endpoints with valid authentication credentials to verify their functionality.
-
Provide clear documentation on how to use and test the authentication schemes, including information on endpoints with restricted authentication methods.
Options Pattern Requirements:
-
Create a custom class, e.g.,
AppSettings.cs
, to represent the custom settings you want to read from theappsettings.json
file. Define the properties within this class to match the expected configuration values. -
Configure the binding of the
AppSettings
class to theappsettings.json
file in theStartup.cs
file using the Options Pattern. -
Implement the following loading strategies for accessing the configuration values:
-
Eager Loading: Demonstrate how to eagerly load the configuration options by injecting them into a controller or service's constructor and accessing the values within the constructor.
-
Explicit Loading: Show how to explicitly load the configuration options within a specific method or property when they are needed.
-
Lazy Loading: Explain how to use the
IOptionsSnapshot
orIOptionsMonitor
to lazily load the configuration values and update them dynamically.
-
-
Provide examples of how to access and use the loaded configuration values in your application logic.
-
Document the steps for adding and modifying custom settings in the
appsettings.json
file, including any data types and constraints.
Deliverables:
- The complete source code of the web application, including authentication and Options Pattern implementations.
- Detailed documentation on how to set up and test the authentication schemes and access custom settings in the
appsettings.json
file using the Options Pattern.