.NET 6, Identity Server 5, client management

54 Views Asked by At

The templates use appsettings.json file to configure the client. The AddClients() method inside AddApiAuthorization() registers an Enumerable.Empty<Client> and then goes to add the clients from the appsettings file.

builder.AddInMemoryClients(Enumerable.Empty<Client>());

Is it possible to change the Enumerable.Empty<Client> to ConcurrentBag<Client> and add clients at run time?

I am probably not thinking about all this correctly.

1

There are 1 best solutions below

0
On

I found the correct way to add clients to dotnet template generated code.

inject IOptions<ApiAuthorizationOptions> and use the _options.Value.Clients object to add the client.

This following example should get you started on the right path.

var props = new Dictionary<string, string>();
props.Add("Profile", "IdentityServerSPA");

clients.Add(new Client
{
    ClientId = "Template",

    AllowedGrantTypes = GrantTypes.Code,
    RequireClientSecret = false,

    RedirectUris = { "/authentication/login-callback" },
    PostLogoutRedirectUris = { "/authentication/logout-callback" },

    AllowedScopes = { "openid", "profile", "TemplateAPI" },

    Properties = props
});

Hope this saves some time for you.