...
Es können mehrere Clients mit unterschiedlichen Konfigurationen registriert werden. Dazu muss pro Konfiguration ein Interface deklariert werden welche . Diese können anschlissend via DependencyInjection konsumiert werden.
Beispielkonfiguration
Code Block | ||
---|---|---|
| ||
public interface IApiV2ClientUserContext : IApiV2Client { } public interface IApiV2ClientAdminContext : IApiV2Client { } public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddApiV2ClientWithHttpContextAuthentication<IApiV2ClientUserContext>(o => { o.ApiBaseUri = new Uri("https://localhost:8000/apiv2"); //o.ExplodeFlatChainProperties = false; //o.AccessDeniedReplacementString = ">>AccessDenied<<"; }); services.AddOpenIdConnectCookieAuthentication<IApiV2ClientUserContext>(options => { options.Authority = "https://coslogin.local:5000"; options.RequireHttpsMetadata = false; // dev only options.ClientId = "[OpenID Client Id]"; options.ClientSecret = "[OpenID Client Secret]"; options.ResponseType = "code"; options.ResponseMode = "form_post"; options.Scope.Add("roles"); options.Scope.Add("profile"); options.Scope.Add("offline_access"); options.SaveTokens = true; options.GetClaimsFromUserInfoEndpoint = true; options.CallbackPath = "/signin-oidc"; options.UsePkce = true; }); services.AddApiV2ClientWithOpenIdPasswordFlow<IApiV2ClientAdminContext>(o => { o.Authority = new Uri("https://coslogin.local:5000"); o.ApiBaseUri = new Uri("https://localhost:8000/apiv2"); o.ClientId = "[OpenID Client Id]"; o.ClientSecret = "[OpenID Client Secret]"; o.Username = "[OpenID User Name]"; o.Password = "[OpenID User Password]"; //o.ExplodeFlatChainProperties = false; //o.AccessDeniedReplacementString = ">>AccessDenied<<"; }); } } |