"ASP. NET core Distributed Project Combat" (i) IdentityServer4 Login center,

Source: Internet
Author: User

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,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.