• Stars
    star
    122
  • Rank 290,730 (Top 6 %)
  • Language
    C#
  • License
    Other
  • Created about 7 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

IdentityServer4 sample with .NET Core and ASP.NET Core 2.0

Goal

My goal was to build a sample with

  • .NET Core 2.0 Console
  • ASP.NET Core 2.0 Web App
  • ASP.NET Core 2.0 Web API

Another goal was to show how the user workflow of application trust should be for "internal" platform services as well as for external clients.

Donations

Please think twice and donate your money to useful institutions such as children's hospices.

Documentation

This sample shows the following workflow:

Workflow

We have an internal area which represents our trusted application environment. Additionally, we see an external example application we do not develop or run.

Consent

All our trusted "internal" applications can access all our APIs. External applications have to be accepted by the user via IdentityServer Consent

IdentityServer4-Sample-Consent

Projects

IdentityServerHost

This ASP.NET Core 2.0 application hosts the IdentityServer. All configurations like users, APIs and clients are static in the SampleConfig.cs file.

The IdentityServer is registered inside of Startup.cs

The sources inside the Quickstart are taken from https://github.com/IdentityServer/IdentityServer4.Quickstart.UI without modifications.

BaseApiSDK

This projects provides basic stuff for accessing an API with the help of a SDK. In a productive environment this would be a NuGet package.

TodoApi

This ASP.NET Core 2.0 application hosts the demo API of todos. All configurations like users, APIs and clients are static in the ApiSampleOptions.cs file.

TodoApiSdk

This projects provides a client TodoApiClient for accessing the TodoApi. It gives you a client for authentication and receiving typed data.

In a productive environment this would be a NuGet package.

PortalWebApp

This ASP.NET Core 2.0 application represents the "Portal Web Application" the user interacts with.

You have a navigation element to receive the tasks from the TodoApi with the help of the TodoApiSdk and you have a navigation element to watch your claims.

Both clicks will redirects you to the IdentityServerHost where you have to log in. Afterwards to will be redirected to this application.

ExternalWebApp

This ASP.NET Core 2.0 application represents an "External Web Application" which is not part of the platform and maybe run by an external company.

This application also provides a navigation element for tasks and claims but after the login the user has to accept the access for this application via via IdentityServer Consent as shown above.

AdminConsoleClient

This is just a simple console application with a usual name based on .NET Core 2.0. It represents a simple client which calls the API with the TodoApiSdk and hard coded user credentials.

In a real world scenario this could be any .NET desktop/server/mobile application.

Run this demo

Clone this repository or download this repository as zip file.

git clone https://github.com/BenjaminAbt/Samples.AspNetCore-IdentityServer4.git

See all information to run this demo below:

Endpoints

Application Url
Todo API http://localhost:9011/api/Tasks Returns a sample task collection
Portal Web http://localhost:9012/ "Internal" Web App
External Web http://localhost:9015/ "External" Web App

Sample Credentials

Username: ben

Password: password

Portal WebApp

Start IdentityServerHost, TodoApi and PortalWebApp via dotnet.exe on your cmd or use the parallel project startup configuration of Visual Studio (right click on the solution -> set startup projects)

VS2017-Startup-Projects

Once started, two browser instances will launch for IdentityServerHost and PortalWebApp. TodoApi will start without a browser instance.

BrowserStart

Click on Tasks in PortalWebApp. Unauthorized it will redirect you to the login site of the IdentityServer. Login

After your login was successful you will be redirected to the Tasks view.

Workflow: the PortalWebApp application uses the TodoApi client to receive the tasks from the TodoApi.

Tasks

External WebApp

Start IdentityServerHost, TodoApi and ExternalWebApp.

Click on Tasks and you will have to log into the IdentityServer and accept the application access request.

Afterwards you will be redirected to the WebApp and will see the tasks loaded from the TodoApi.

Admin Console

Start IdentityServerHost, TodoApi, AdminConsoleClient

VS2017-Startup-Admin

The console will now authenticate your instance with the hard-coded credentials and will request the TodoApi to get the tasks.

Admin

License

Released under the MIT license.

Versions

  • 1.1 (2017-10-07): Updated to stable release of IdentityServer 2.0
  • 1.0 (2017-09-26): Published

More Repositories

1

SustainableCode

Sustainable Code Samples and Patterns by BEN ABT
C#
50
star
2

hcaptcha

hCaptcha for .NET and ASP.NET Core (not official)
C#
24
star
3

2018-Talks-ModernApiDevelopment

C#
17
star
4

AspNetCoreEnterprisePlatform

C#
10
star
5

AssemblyMetadata

Small sample how to use Source Code Generators in .NET
C#
8
star
6

StrongOf

StrongOf helps to implement primitives as a strong type that represents a domain object (e.g. UserId, EmailAddress, etc.). It is a simple class that wraps a value and provides a few helper methods to make it easier to work with. In contrast to other approaches, StrongOf is above all simple and performant - and not over-engineered.
C#
7
star
7

Twitch.MediatR

CQRS sample implementation of Twitch with AspNetCore and MediatR
C#
4
star
8

efcore-best-practises

EF Core Best Practises by BEN ABT
C#
3
star
9

Hangfire.ConsoleHost

Extension to run Hangfire with Dependency Injection in a .NET Core Host
C#
3
star
10

Windows-10-Disable-Game-Mode

3
star
11

ToxicDetectorSampleMLNET

Text Sentiment Sample with .NET and ML.NET
C#
2
star
12

samples-aspnetcore-cloudflare-turnstile

ASP.NET Core Form protection with Cloudflare's Turnstile - https://schwabencode.com/blog/2024/02/29/dotnet-aspnetcore-cloudflare-turnstile
C#
2
star
13

MicrosoftBand2HeartRateApp

Microsoft Band 2 HeartRate Monitor Example App
C#
2
star
14

docker-mssql

Dockerfile
2
star
15

RefitInheritance

C#
1
star
16

AzureDevOps-YamlBuildSamples

1
star
17

DotNet-FileEncoder

mass change of file encoding
C#
1
star
18

gittest

1
star
19

ThrowAwayLogger

A very simple ILogging mock mechanism.
C#
1
star
20

Sample-WinForms-RxNET-SPS

Small simplified sample to show the usage of Rx.NET in a WinForms App
C#
1
star
21

Talks.AspNetCore-3-Basics

HTML
1
star
22

DeveloperCircle.Website

HTML
1
star
23

Samples.AzureServiceBusConsole

http://schwabencode.com/artikel/azure/azure-service-bus-queue-warteschlangen-azure/
C#
1
star
24

Ubuntu-Container-Management

Shell
1
star