Introduction
The API is configured via .NET dependency injection. Depending on the Openld client configuration and desired authentication method, the configuration can look different.
...
The URL under which the API can be reached, Example: https://localhost:8000/apiv2/latest
ExplodeFlatChainProperties
...
Example: /servicedmcore/CoreIdentity/2/?fields=Id,Nachname,CoreIdentityType.Id
ExplodeFlatChainProperties = true | ExplodeFlatChainProperties = false |
---|
Code Block |
---|
| {
"ci_family_name": {
"was_access_denied": false,
"value": "Testikus"
},
"id": 20,
"core_identity_type": {
"id": {
"was_access_denied": false,
"value": 1
}
}
} |
| Code Block |
---|
| {
"ci_family_name": {
"was_access_denied": false,
"value": "Testikus"
},
"core_identity_type.id": {
"was_access_denied": false,
"value": 1
},
"id": 20
} |
|
AccessDeniedReplacementString
...
Example: /servicedmcore/CoreIdentity/2/?fields=Id,Nachname,Language
| AccessDeniedReplacementString=">Denied<" |
---|
Code Block |
---|
| {
"ci_family_name": {
"was_access_denied": true,
"value": null
},
"id": 20,
"core_identity_type": {
"id": {
"was_access_denied": false,
"value": 1
}
}
} |
| Code Block |
---|
| {
"ci_family_name": ">Denied<",
"id": 20,
"core_identity_type": {
"id": 1
}
} |
|
.NET Core configuration
Required assemblies
...
Code Block |
---|
|
public void ConfigureServices(IServiceCollection services)
{
services.AddApiV2ClientWithHttpContextAuthentication(o =>
{
o.ApiBaseUri = new Uri("https://localhost:8000/apiv2/latest");
//o.ExplodeFlatChainProperties = false;
//o.AccessDeniedReplacementString = ">>AccessDenied<<";
});
services.AddOpenIdConnectCookieAuthentication<IApiV2Client>(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;
});
} |
...
Code Block |
---|
|
public void ConfigureServices(IServiceCollection services)
{
services.AddApiV2ClientWithOpenIdPasswordFlow(o =>
{
o.Authority = new Uri("https://coslogin.local:5000");
o.ApiBaseUri = new Uri("https://localhost:8000/apiv2/latest");
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<<";
});
} |
...
Code Block |
---|
|
public void ConfigureContainer(IWindsorContainer container)
{
container.AddApiV2ClientWithOpenIdPasswordFlow(o =>
{
o.Authority = new Uri("https://coslogin.local:5000");
o.ApiBaseUri = new Uri("https://localhost:8000/apiv2/latest");
o.ClientId = "[OpenID Client Id]";
o.ClientSecret = "[OpenID Client Secret]";
o.Username = "[OpenID User Name]";
o.Password = "[OpenID User Password]";
});
} |
...
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/latest");
//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/latest");
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<<";
});
}
} |