aeongt710/dotnet-roadmap

Authentication Schemes and Options Pattern Implementation

Closed this issue · 4 comments

Authentication Scheme Requirements:

  1. Create a new ASP.NET Core web application.

  2. Configure the authentication schemes in the Startup.cs file, specifying Cookie Authentication as the default scheme.

  3. 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.
  4. Ensure that the authentication middleware and services are properly configured to handle both cookies and JWT tokens.

  5. Demonstrate the ability to access user data or roles based on the authentication scheme used for each endpoint.

  6. Test the endpoints with valid authentication credentials to verify their functionality.

  7. Provide clear documentation on how to use and test the authentication schemes, including information on endpoints with restricted authentication methods.


Options Pattern Requirements:

  1. Create a custom class, e.g., AppSettings.cs, to represent the custom settings you want to read from the appsettings.json file. Define the properties within this class to match the expected configuration values.

  2. Configure the binding of the AppSettings class to the appsettings.json file in the Startup.cs file using the Options Pattern.

  3. 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 or IOptionsMonitor to lazily load the configuration values and update them dynamically.

  4. Provide examples of how to access and use the loaded configuration values in your application logic.

  5. 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.