Implement an OAuth 2.0 Server (Part 01)
Welcome to the first part of a series of posts where we will implement an OAuth 2 Server using AspNet.Security.OpenIdConnectServer.
The creator of the library, Kevin Chalet, has an excellent series of blog posts, that you are encouraged to read for more information, with less of a hands-on approach.
The final product is available here on GitHub, and at the end of each step the project as completed up to that point will be available on its respective branch.
For a live demonstration of this application - visit the hosted version on Azure, where you can do everything we’ll describe.
Tutorial Table of Contents
- Introduction
- Project Setup and Dependency Downloads
- SQLite and Initial Migration
- Public API Barebones Setup
- Adding Models
- OAuth Client CRUD - Controller and ViewModels
- OAuth Client CRUD - Views
- Adding Client Scopes
- Authorization Provider - Authorize Methods
- Authorization Provider - Token Methods
- Services
- Authorization Request Accept/Deny View
- Claims, Identity, Authentication Tickets
- Adding OAuth Token Validation
- Scope Authorization with Policies, Requirements and Handlers
- Token Revocation
- Rate Limiting - Models and Provider Changes
- Rate Limiting - Attribute Creation
- Pushing to Azure
Concepts
Along the way you’ll be exposed to these concepts:
- Beginner Concepts:
- curl
- CRUD
- REST APIs
- Intermediate Concepts
- Razor Pages 2.0
- Authentication
- OAuth 2
- Entity Framework Core
- Rate Limiting
- Advanced Concepts
- Identity
- Claims
- Authentication Schemes
Libraries
We’ll be using the following libraries in our application:
- AspNet.Security.OpenIdConnect.Extensions
- AspNet.Security.OpenIdConnect.Primitives
- AspNet.Security.OpenIdConnect.Server
- AspNet.Security.OAuth.Introspection
- AspNet.Security.OAuth.Validation
What the application will be able to do
At a high level, our final application will be able to do these things:
- Users will be able to register and login on the website, with persisted login sessions via cookie authentication.
- Users will be able to create/delete OAuth Client Applications, give them a name, a description, and a list of redirect URIs.
- Users will also be able to edit the description and regenerate the
client secret
. - Our server will support issuing OAuth 2.0 access tokens to those applications with the three major flows:
- Client Credentials
- Implicit
- Authorization Code
- Our server will have a small authenticated-access API that utilizes OAuth Scopes
- Finally, we’ll support rate limiting of our endpoints
Public API
We’ll have a small public API that supports the following unauthenticated, authenticated, unscoped, and scoped endpoints:
- Unauthenticated Methods
- GET
api/v1/hello
- Returns
"Hello"
in the body.
- Returns
- GET
- Authenticated Methods
- Unscoped Methods
- GET
api/v1/clientcount
- Returns
number of clients you've registered
in the body
- Returns
- GET
- Scoped Methods
- GET
api/v1/birthdate
- Returns the
user's birthdate
in the body
- Returns the
- GET
api/v1/email
- Returns the
user's email
- Returns the
- PUT
api/v1/email
- Changes the
user's email
- Changes the
- PUT
api/v1/birthdate
- Changes the
user's birthdate
- Changes the
- GET
api/v1/me
- gets the user object, requires no scopes but additional information is returned if more scopes are present.
- GET
- Unscoped Methods
Moving On
In the next section we’ll set up the basic project structure and download our libraries.
Posts in this series
- Implement an OAuth 2.0 Server (Part 19)
- Implement an OAuth 2.0 Server (Part 18)
- Implement an OAuth 2.0 Server (Part 17)
- Implement an OAuth 2.0 Server (Part 16)
- Implement an OAuth 2.0 Server (Part 15)
- Implement an OAuth 2.0 Server (Part 14)
- Implement an OAuth 2.0 Server (Part 13)
- Implement an OAuth 2.0 Server (Part 12)
- Implement an OAuth 2.0 Server (Part 11)
- Implement an OAuth 2.0 Server (Part 10)
- Implement an OAuth 2.0 Server (Part 09)
- Implement an OAuth 2.0 Server (Part 08)
- Implement an OAuth 2.0 Server (Part 07)
- Implement an OAuth 2.0 Server (Part 06)
- Implement an OAuth 2.0 Server (Part 05)
- Implement an OAuth 2.0 Server (Part 04)
- Implement an OAuth 2.0 Server (Part 03)
- Implement an OAuth 2.0 Server (Part 02)
- Implement an OAuth 2.0 Server (Part 01)