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.slnand open with Visual Studio 2017 - Navigate to Build - Rebuild Solution
- Navigate to Tools - Extensions and Updates..
- Click
Onlinelocated on the left side and search forOpen Command Lineand install (restart Visual Studio) - Click on
ContosoUniversity.APIproject on the Solution Explorer, and pressALT + SPACEto 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/tokenCreate Keys & Values in
Bodytab,x-www-form-urlencodedsection using admin account and copyaccess_tokenvalue
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...

