Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

var builder = DistributedApplication.CreateBuilder(args);

var idp = builder.AddProject<Projects.IdentityServerHost>("identityserverhost");
Expand All @@ -6,6 +9,7 @@
.WaitFor(idp);

builder.AddProject<Projects.Client>("client")
.WaitFor(idp);
.WaitFor(idp)
.WithEnvironment("IS_IN_ASPIRE", true.ToString());

builder.Build().Run();
8 changes: 7 additions & 1 deletion IdentityServer/v7/Basics/ClientCredentials/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ Key takeaways:
- how to use a shared secret
- how to use an access token

Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.
Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.

## How to Run

1. Run the Aspire project
1. Notice the `client` application is not running. It has already run and completed.
1. View the console output of the `client` application. Run it again if you would like.
24 changes: 21 additions & 3 deletions IdentityServer/v7/Basics/ClientCredentials/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;

using Client;

using Duende.IdentityModel.Client;

Console.Title = "Console Client Credentials Flow";

var response = await RequestTokenAsync();
response.Show();

Console.ReadLine();
WaitToBegin();
await CallServiceAsync(response.AccessToken);

static async Task<TokenResponse> RequestTokenAsync()
{
var client = new HttpClient();

var disco = await client.GetDiscoveryDocumentAsync(Urls.IdentityServer);
if (disco.IsError) throw new Exception(disco.Error);
if (disco.IsError)
{
throw new Exception(disco.Error);
}

var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
{
Expand All @@ -32,7 +37,11 @@ static async Task<TokenResponse> RequestTokenAsync()
Scope = "scope1"
});

if (response.IsError) throw new Exception(response.Error);
if (response.IsError)
{
throw new Exception(response.Error);
}

return response;
}

Expand All @@ -49,3 +58,12 @@ static async Task CallServiceAsync(string token)
"\n\nService claims:".ConsoleGreen();
Console.WriteLine(response.PrettyPrintJson());
}

static void WaitToBegin()
{
//When not run with Aspire, wait for user to initiate this client so services are started
if (!string.Equals(Environment.GetEnvironmentVariable("IS_IN_ASPIRE"), true.ToString()))
{
Console.ReadLine();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

var builder = DistributedApplication.CreateBuilder(args);

var idp = builder.AddProject<Projects.IdentityServerHost>("identityserverhost");
Expand All @@ -6,6 +9,7 @@
.WaitFor(idp);

builder.AddProject<Projects.Client>("client")
.WaitFor(idp);
.WaitFor(idp)
.WithEnvironment("IS_IN_ASPIRE", true.ToString());

builder.Build().Run();
6 changes: 6 additions & 0 deletions IdentityServer/v7/Basics/Introspection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ This sample shows how to use the reference tokens instead of JWTs.
- configure an API to accept and validate reference tokens

Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.

## How to Run

1. Run the Aspire project
1. Notice the `client` application is not running. It has already run and completed.
1. View the console output of the `client` application. Run it again if you would like.
24 changes: 21 additions & 3 deletions IdentityServer/v7/Basics/Introspection/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;

using Client;

using Duende.IdentityModel.Client;

var response = await RequestTokenAsync();
response.Show();

Console.ReadLine();
WaitToBegin();
await CallServiceAsync(response.AccessToken);

static async Task<TokenResponse> RequestTokenAsync()
{
var client = new HttpClient();

var disco = await client.GetDiscoveryDocumentAsync(Urls.IdentityServer);
if (disco.IsError) throw new Exception(disco.Error);
if (disco.IsError)
{
throw new Exception(disco.Error);
}

var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
{
Expand All @@ -30,7 +35,11 @@ static async Task<TokenResponse> RequestTokenAsync()
Scope = "scope2"
});

if (response.IsError) throw new Exception(response.Error);
if (response.IsError)
{
throw new Exception(response.Error);
}

return response;
}

Expand All @@ -47,3 +56,12 @@ static async Task CallServiceAsync(string token)
"\n\nService claims:".ConsoleGreen();
Console.WriteLine(response.PrettyPrintJson());
}

static void WaitToBegin()
{
//When not run with Aspire, wait for user to initiate this client so services are started
if (!string.Equals(Environment.GetEnvironmentVariable("IS_IN_ASPIRE"), true.ToString()))
{
Console.ReadLine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ This sample shows how to use the client_credentials grant type with JWT-based cl
- configure IdentityServer to accept a JWT as a client secret

Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.

## How to Run

1. Run the Aspire project
1. Notice the `client` application is not running. It has already run and completed.
1. View the console output of the `client` application. Run it again if you would like.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
using System.Net.Http;
using System.Security.Claims;
using System.Threading.Tasks;

using Client;

using Duende.IdentityModel;
using Duende.IdentityModel.Client;

using Microsoft.IdentityModel.Tokens;

// would normally load from a secure data store
Expand Down Expand Up @@ -40,7 +43,10 @@ static async Task<TokenResponse> RequestTokenAsync(SigningCredentials signingCre
var client = new HttpClient();

var disco = await client.GetDiscoveryDocumentAsync(Urls.IdentityServer);
if (disco.IsError) throw new Exception(disco.Error);
if (disco.IsError)
{
throw new Exception(disco.Error);
}

var clientToken = CreateClientToken(signingCredentials, "jwt.client.credentials.sample", disco.Issuer);
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
Expand All @@ -56,7 +62,11 @@ static async Task<TokenResponse> RequestTokenAsync(SigningCredentials signingCre
Scope = "scope1"
});

if (response.IsError) throw new Exception(response.Error);
if (response.IsError)
{
throw new Exception(response.Error);
}

return response;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

var builder = DistributedApplication.CreateBuilder(args);

var idp = builder.AddProject<Projects.IdentityServerHost>("identityserverhost");
Expand Down
8 changes: 8 additions & 0 deletions IdentityServer/v7/Basics/MvcBackChannelLogout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ This sample shows how to use back-channel logout notifications.
- how to leverage events on the cookie handler to invalidate the user session

Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.

## How to Run

1. Run the Aspire project
1. Open a browser tab to th `client` application at `https://localhost:44300/`.
1. Click on the 'Secure' tab. You will be redirected to the IdentityServer application hosted at `https://localhost:5001`.
1. Login with username `bob` and password `bob`.
1. You will be redirected back to the `client` application's `/secure` page.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Client;

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
Expand Down
11 changes: 10 additions & 1 deletion IdentityServer/v7/Basics/MvcBasic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ This sample shows how to use the authorization_code grant type. This is typicall
- manually refresh tokens


Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.
Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.

## How to Run

1. Run the Aspire project
1. Open a browser tab to th `client` application at `https://localhost:44300/`.
1. Click on the 'Secure' tab. You will be redirected to the IdentityServer application hosted at `https://localhost:5001`.
1. Login with username `bob` and password `bob`.
1. You will be redirected back to the `client` application's `/secure` page.
1. Click the `Call API` button to make a secure call to the Web API using the token provided by IdentityServer.
2 changes: 2 additions & 0 deletions IdentityServer/v7/Basics/MvcBasic/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Client;

using Duende.IdentityModel.Client;

using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.IdentityModel.Tokens;
Expand Down
11 changes: 10 additions & 1 deletion IdentityServer/v7/Basics/MvcJarJwt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ This sample shows how to use signed authorize requests, and JWT-based authentica
- configure a client in IdentityServer to share key material for both front- and back-channel


Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.
Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.

## How to Run

1. Run the Aspire project
1. Open a browser tab to th `client` application at `https://localhost:44300/`.
1. Click on the 'Secure' tab. You will be redirected to the IdentityServer application hosted at `https://localhost:5001`.
1. Login with username `bob` and password `bob`.
1. You will be redirected back to the `client` application's `/secure` page.
1. Click the `Call API` button to make a secure call to the Web API using the token provided by IdentityServer.
11 changes: 10 additions & 1 deletion IdentityServer/v7/Basics/MvcPar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ This sample shows how to use Pushed Authorization Requests (PAR).
.NET 9 and higher versions have support for PAR built-in, and the ASP.NET Core OIDC authentication handler will automatically use PAR when the authority supports it, based on the discovery metadata.


Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.
Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.

## How to Run

1. Run the Aspire project
1. Open a browser tab to th `client` application at `https://localhost:44300/`.
1. Click on the 'Secure' tab. You will be redirected to the IdentityServer application hosted at `https://localhost:5001`.
1. Login with username `bob` and password `bob`.
1. You will be redirected back to the `client` application's `/secure` page.
1. Click the `Call API` button to make a secure call to the Web API using the token provided by IdentityServer.
11 changes: 10 additions & 1 deletion IdentityServer/v7/Basics/MvcTokenManagement/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ You can also turn on debug tracing to get more insights in the token management
- use Duende.AccessTokenManagement to automate refreshing tokens


Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.
Please take a look [here](https://docs.duendesoftware.com/identityserver/samples) to learn about the structure of our samples and how to run them.

## How to Run

1. Run the Aspire project
1. Open a browser tab to th `client` application at `https://localhost:44300/`.
1. Click on the 'Secure' tab. You will be redirected to the IdentityServer application hosted at `https://localhost:5001`.
1. Login with username `bob` and password `bob`.
1. You will be redirected back to the `client` application's `/secure` page.
1. Click the `Call API` button to make a secure call to the Web API using the token provided by IdentityServer.
2 changes: 0 additions & 2 deletions IdentityServer/v7/Configuration/IdentityServerHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Globalization;
using IdentityServer;
using Microsoft.Extensions.Hosting;

var builder = WebApplication.CreateBuilder(args);

Expand Down
Loading
Loading