RESTful API using AspNetCore.Identity and OpenID Connect
- ASP.NET Core 2.0
- Entity Framework Core 2.0
- Code First Migration
- OpenIdConnect.Server
- AspNetCore.Identity 2.0
- EntityFrameworkCore.SqlServer
- Automapper
Referenced Microsoft and chsakell's REST API best practice
- Clone or download this project
- Click
ContosoUniversity.sln
and open with Visual Studio 2017 - Navigate to Build - Rebuild Solution
- Navigate to Tools - Extensions and Updates..
- Click
Online
located on the left side and search forOpen Command Line
and install (restart Visual Studio) - Click on
ContosoUniversity.API
project on the Solution Explorer, and pressALT + SPACE
to open up CLI - Run this migration command:
dotnet ef migrations add InitialDatabase -c ContosoContext
- Run another command which creates database:
dotnet ef database update -c ContosoContext
- In
Startup.cs
, uncommentseeder.InitializeData().Wait();
from Configure method - Press F5 to run the project. (Make sure ContosoUniversity.API is set as startup project)
- Separation of concerns is widely applied so the codes are not tightly coupled. (Ex: repository patterns)
- Used Automapper to prevent from over-posting attacks
- Fluent validation is used
- RESTful HTTP API using JSON as a data format
- JWT(JSON Web Tokens) based security (Authentication, Authorization & API calls)
Use Postman or other API testing tools
-
Retrieve all instructors:
GET
http://localhost:51089/api/instructors
-
Access Apis based on a role (Admin or User):
POST
http://localhost:51089/connect/token
Create Keys & Values in
Body
tab,x-www-form-urlencoded
section using admin account and copyaccess_token
value
GET http://localhost:51089/api/admin
where it is decorated with [Authorize(Roles = "Admin")]
attribute.
Create Key & Value clicking Headers
tab. Paste the access_token value in the Value textbox: Bearer eyjhb...