YellowNotes icon indicating copy to clipboard operation
YellowNotes copied to clipboard

Sample ASP.NET Web API project with OAuth authentication and many other extensions.

YellowNotes

Sample ASP.NET Web API project with OAuth authentication and many other extensions.

Table of contents

  1. The basics of API (CRUD)
  2. Validation
  3. Authentication and authorization
  4. Other
  5. Samples
  6. Useful links

1. The basics of API (GoodNotesController)

  • Create -> Post
  • Read -> Get
  • Update -> Put
  • Delete -> Delete

2. Validation

  • Basic validation (via DataAnnotations attributes)
  • ModelState validation (ValidateModelStateAttribute)
  • Model empty validation (CheckModelForNullAttribute)
  • Action parameters validation (ActionParametersValidationAttribute)

3. Authentication and authorization

  • Access Token (OAuth bearer token authentication using OWIN middleware) (SimpleAuthorizationServerProvider)
  • Client credentials validation
  • Token custom parameter
  • Authentication Ticket custom property
  • Custom claim
  • Refresh Token (SimpleRefreshTokenProvider)
  • Custom Authorize attribute (SimpleAuthorizeAttribute)

45. Other

  • Dependency Injection with Autofac (DependencyConfig)
  • API documentation page with Swagger (SwaggerConfig)
  • API exceptions handling (RequestExceptionAttribute)
  • Working CORS (Cross-Origin Resource Sharing) implementation (CorsProvider)
  • Simple Owin middleware to rewrite header from request to response (CorrelationIdHeaderRewriterMiddleware)

5. Samples

Token generation

Token generation

Access to resource denied

Access denied

Access to resource granted

Access granted

Refresh Token utilise

Refresh Token utilise

Model validation

Model empty validation

CORS (Cross-Origin Resource Sharing)

CORS

API Documentation page

API documentation page


6. Useful links

  • HTTP Status Codes: https://www.restapitutorial.com/httpstatuscodes.html
  • Choosing an HTTP Status Code: ~~http://racksburg.com/choosing-an-http-status-code~~ https://www.ruilog.com/notebook/view/f21862318f93.html