skoruba / IdentityServer4.Admin

The administration for the IdentityServer4 and Asp.Net Core Identity
MIT License
3.56k stars 1.15k forks source link

How to use identity server with asp.net #493

Open sbn111 opened 4 years ago

sbn111 commented 4 years ago

How to use your identity server with asp.net. I already have my project and I want to know how to implement your identity server project on my asp.net core web application. Kindly briefly explain how to do that. I already saw readme but it cant understandable. Thanks, Waiting for your replay...

skoruba commented 4 years ago

Did you try use dot net new template? This operation generates whole project under solution. You can move this projects under your solution which is already exist.

sbn111 commented 4 years ago

Did you try use dot net new template? This operation generates whole project under solution. You can move this projects under your solution which is already exist. Hi sir, I am a beginner. I don't know much about Docker and Asp.net. With dot net new template command I got the whole project. But I don't know which file I need to include in my solution. I am having asp.net core web application(mvc) project on my computer. I want to use your Identity Server for my project. Kindly explain more clearly with my requirements. This would be used for everyone who needs this requirement. Thanks in advance. Waiting for your reply....

yiskang commented 4 years ago

Here are some materials from the IdentityServer4 Documentation (based on beta7 template):

The only one thing you have to care about is changing the URL of the Authority property to your STS server. Besides, to take advantage of this project, you have to install the dot net core project template via:

dotnet new -i Skoruba.IdentityServer4.Admin.Templates::1.0.0-beta7

Afterward, create a new skoruba.is4admin project with this command:

dotnet new skoruba.is4admin --name MyProject --title MyProject --adminemail "admin@example.com" --adminpassword "Pa$$word123" --adminrole MyRole --adminclientid MyClientId --adminclientsecret MyClientSecret --dockersupport true

While the project is created successfully, you can open Visual Studio to compile it. There will be three C# projects at least in the Identity server admin solution. (If you're using the last build of this project, you will get 13 C# projects in the solution project in total). The step to run the project:

  1. Modify ConnectionStrings in the appsettings.json of these C# projects.

    • Skoruba.IdentityServer4.Admin
    • Skoruba.IdentityServer4.Admin
    • Skoruba.IdentityServer4.STS.Identity
  2. Open your command line prompt, and chroot to Skoruba.IdentityServer4.Admin
  3. Run EFcore migration:
dotnet ef database update -c AdminLogDbContext
dotnet ef database update -c IdentityServerConfigurationDbContext
dotnet ef database update -c IdentityServerPersistedGrantDbContext
  1. Type dotnet run /seed to seed database
  2. Compile the Identity server admin solution in Visual Studio
  3. Mouse right-click on these C# projects in sequence, then left-click on Debug > Start a new instance:

    • Skoruba.IdentityServer4.STS.Identity
    • Skoruba.IdentityServer4.Admin
    • Skoruba.IdentityServer4.Admin.Api

ref: https://github.com/skoruba/IdentityServer4.Admin#installation-via-dotnet-new-template

  1. Open your web browser, type http://localhost:9000, and press enter. You will see a login page of the identity server.

  2. Type the admin password you assigned while creating Identity server admin project with the dot net template command, then the admin website will say hi to you!

Hope it helps!

Note. The Skoruba prefix will be changed to the name argument of the dot net template command

sbn111 commented 4 years ago

Thank you. It worked for me. And one more doubt, can I add custom field in the role and how to get custom field values.

mehyaa commented 4 years ago

Thank you. It worked for me. And one more doubt, can I add custom field in the role and how to get custom field values.

You should use Role claims.