Einleitung
Die API wird via .net Dependency-Injection konfiguriert. Abhängig von der OpenId-Client-Konfiguration und dem gewünschten Authentifizierungsverfahren kann die Konfiguration anders aussehen.
Benötigte Assemblies
iTsense.Moving.Common.NetStandard
iTsense.Moving.ApiV2.Common
iTsense.Moving.ApiV2.Client
iTsense.Moving.ApiV2.Client.NetCore
Beispielkonfiguration mit Authentifizierung via HTTP-Userkontext
public void ConfigureServices(IServiceCollection services) { services.AddApiV2Client< ApiV2OpenIdClient<ApiV2OpenIdHttpContextClientOptions>, ApiV2OpenIdHttpContextClientOptions >(o => { o.ApiBaseUri = new Uri("https://localhost:8000/apiv2"); //Authority / ClientId / ... not required as Token is handled by HttpContext }); services.AddOpenIdConnectCookieAuthentication(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; }); }
Beispielkonfiguration mit Authentifizierung via statischem API-Benutzer
public void ConfigureServices(IServiceCollection services) { services.AddApiV2Client< ApiV2OpenIdClient<ApiV2OpenIdPasswordFlowClientOptions>, ApiV2OpenIdPasswordFlowClientOptions >(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]"; }); }