Information
OAuth2 Process: http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html
Blog Park Xiao Chen's Chinese document about IDENTITYSERVER4 address: http://www.cnblogs.com/stulzq/p/8119928.html
Docker Chinese document https://yeasy.gitbooks.io/docker_practice/content/
Next we use the client mode to implement a IDENTITYSERVER4 authorization
Client-side mode (Credentials Grant) authorized server
Steps:
Add NuGet Package: IdentityServer4 Add startup configuration Add Config.cs Configuration class change identity server4 configuration Add Client Configuration
First step: Add a NuGet package: IdentityServer4
First, create a new WEBAPI project Identityservercenter
new Webapi--name identityservercenter
We can use the Ctrl+p key in Vscode to open the command panel. Then enter NuGet Press ENTER, enter identityserver4 and press ENTER to select version to install
"Note: You can not reference IdentityServer4 in a class until you reopen the folder item"
Step Two: Add the startup configuration
Reference namespaces:
using IdentityServer4;
Add Identityserver Dependency Injection
Services. Addidentityserver () . Adddevelopersigningcredential (); // To add developer signing credentials
Using Identityserver
App. Useidentityserver (); // using Identityserver
We can set the address of the current API to http://localhost:5000 in Program.cs
Step three: Add the Config.cs configuration class
We then add a Config.cs class, which is used to initialize the Identityserver
usingSystem.Collections;usingSystem.Collections.Generic;usingIdentityServer4;usingIdentityserver4.models;namespaceidentityservercenter{ Public classConfig {//All access to the resource Public StaticIenumerable<apiresource>getresources () {return NewList<apiresource> { NewApiresource ("API","My Api") }; } //Client Public StaticIenumerable<client>getclients () {return NewList<client> { NewClient () {ClientId="Client", Allowedgranttypes= Granttypes.clientcredentials,//mode: The simplest modeclientsecrets={//private Key NewSecret ("Secret". SHA256 ())}, Allowedscopes={//resource that can be accessed "API" } } }; } }}
View CodeFourth Step: Change the identity server4 configuration
Services. Addidentityserver () . Adddevelopersigningcredential ()// Add developer signing credentials . Addinmemoryapiresources (Config.getresources ());//Add Memory Apiresource
Fifth Step: Add Client Configuration
Services. Addidentityserver () . Adddevelopersigningcredential ()// Add developer signing credentials . Addinmemoryapiresources (Config.getresources ())// Add memory apiresource . Addinmemoryclients (Config.getclients ());//Add Memory client
This is after we execute dotnet run through Http://localhost:5000/.well-known/openid-configuration access; You can see that it is a restful API;
"ASP. NET core Distributed Project Combat" (i) IdentityServer4 Login center,