From the course: Building and Securing RESTful APIs in ASP.NET Core

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Add a token endpoint

Add a token endpoint - ASP.NET Core Tutorial

From the course: Building and Securing RESTful APIs in ASP.NET Core

Start my 1-month free trial

Add a token endpoint

- [Instructor] Now that we've added ASP.NET Core identity and OpenIdict to the project, we have all the pieces we need to build a token route. The token route will let the client exchange the user's credentials for an access token. I've added a controller called token controller to the project using some code from the OpenIdict samples. You can find it in the exercise files for this video. The token controller has one post route called TokenExchange. This method does a few things, so let's go through the steps one by one to understand everything that it's doing. First, this method checks to make sure that the incoming request is in fact an OpenIdConnect password grant request. If it's not, it'll return an error to the user. Next it looks up the user's user name to make sure the user actually exists in the database, and if not, return an error. Then it checks to make sure that the user is allowed to sign in, and if not, returns an error. It similarly checks to make sure the user is not…

Contents