{"id":23841860,"url":"https://github.com/a-postx/delobytes.aspnetcore.infrastructure","last_synced_at":"2025-09-07T17:32:21.524Z","repository":{"id":65382470,"uuid":"429315375","full_name":"a-postx/Delobytes.AspNetCore.Infrastructure","owner":"a-postx","description":"Компоненты инфраструктурного слоя для .net core: аутентификация на базе KeyCloak, Auth0.","archived":false,"fork":false,"pushed_at":"2023-09-15T23:59:35.000Z","size":87,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-02T07:24:26.207Z","etag":null,"topics":["auth0","authentication","jwt","keycloak"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a-postx.png","metadata":{"files":{"readme":"README.en.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-18T06:04:47.000Z","updated_at":"2024-03-05T19:20:44.000Z","dependencies_parsed_at":"2023-01-20T13:55:34.031Z","dependency_job_id":null,"html_url":"https://github.com/a-postx/Delobytes.AspNetCore.Infrastructure","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-postx%2FDelobytes.AspNetCore.Infrastructure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-postx%2FDelobytes.AspNetCore.Infrastructure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-postx%2FDelobytes.AspNetCore.Infrastructure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-postx%2FDelobytes.AspNetCore.Infrastructure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a-postx","download_url":"https://codeload.github.com/a-postx/Delobytes.AspNetCore.Infrastructure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232236282,"owners_count":18492907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth0","authentication","jwt","keycloak"],"created_at":"2025-01-02T18:21:32.026Z","updated_at":"2025-01-02T18:21:35.330Z","avatar_url":"https://github.com/a-postx.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Delobytes.AspNetCore.Infrastructure\nInfrastructure layer components for .Net Core web-API applications.\n\n[RU](README.md), [EN](README.en.md)\n\n## Installation\n\nThe fastest way to add package to your app is via [NuGet](https://www.nuget.org/packages/Delobytes.AspNetCore.Infrastructure):\n\n    dotnet add package Delobytes.AspNetCore.Infrastructure\n\n## Usage\n\n## KeyCloak Authentication\nAdd JWT-authentication based on KeyCloak. You can add claim names that should be taken from JWT-token and added to the user identity if needed.\n\n1. Set up KeyCloak, create realm and open its endpoint configuration page (/.well-known/openid-configuration).\n\n2. Add KeyCloak authentication handler to your application:\n\n```csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddKeyCloakAuthentication(\"SchemeName\", true, options =\u003e\n        {\n            options.Authority = \"https://mykeycloakinstallation.com/auth/realms/myrealm\"; //\"issuer\" endpoint\n            options.Audience = \"account\";\n            options.OpenIdConfigurationEndpoint = \"https://mykeycloakinstallation.com/auth/realms/myrealm/.well-known/openid-configuration\";\n            options.TokenValidationParameters = new TokenValidationOptions\n            {\n                RequireExpirationTime = true,\n                RequireSignedTokens = true,\n                ValidateIssuer = true,\n                ValidIssuer = \"https://mykeycloakinstallation.com/auth/realms/myrealm\",\n                ValidateAudience = true,\n                ValidAudience = \"account\",\n                ValidateIssuerSigningKey = true,\n                ValidateLifetime = true,\n                ClockSkew = TimeSpan.FromMinutes(2),\n            };\n        });\n}\n\npublic void Configure(IApplicationBuilder application)\n{\n    application\n        .UseAuthentication();     \n}\n```\n\n3. Set attribute Authorize to a method or controller:\n\n```csharp\n[Route(\"[controller]\")]\n[ApiController]\n[Authorize]\npublic class HomeController : ControllerBase\n{\n    [HttpPost]\n    public Task\u003cIActionResult\u003e PostInfoAsync(\n        [FromServices] IPostClientInfoAh handler,\n        [FromBody] InfoSm infoSm,\n        CancellationToken cancellationToken)\n    {\n        return handler.ExecuteAsync(infoSm, cancellationToken);\n    }\n}\n```\n\n## Auth0 Authentication\nAdd JWT-authentication based on Auth0. You can add claim names that should be taken from JWT-token and added to the user identity if needed.\n\n1. Register on Auth0, create application and open its endpoint configuration page (/.well-known/openid-configuration).\n\n2. Add authentication handler:  \n\n```csharp\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddAuth0Authentication(\"SchemeName\", true, options =\u003e\n        {\n            options.Authority = \"https://dev-xxxxxxxx.eu.auth0.com\";\n            options.Audience = \"https://myapp-audience.com\";\n            options.OpenIdConfigurationEndpoint = \"https://dev-xxxxxxxx.eu.auth0.com/.well-known/openid-configuration\";\n            options.TokenValidationParameters = new TokenValidationOptions\n            {\n                RequireExpirationTime = true,\n                RequireSignedTokens = true,\n                ValidateIssuer = true,\n                ValidIssuer = \"https://dev-xxxxxxxx.eu.auth0.com/\",\n                ValidateAudience = true,\n                ValidAudience = \"account\",\n                ValidateIssuerSigningKey = true,\n                ValidateLifetime = true,\n                ClockSkew = TimeSpan.FromMinutes(2),\n            };\n        });\n}\n\npublic void Configure(IApplicationBuilder application)\n{\n    application\n        .UseAuthentication();     \n}\n```\n\n3. Set attribute Authorize to a method or controller:\n\n```csharp\n[Route(\"[controller]\")]\n[ApiController]\n[Authorize]\npublic class HomeController : ControllerBase\n{\n    [HttpPost]\n    public Task\u003cIActionResult\u003e PostInfoAsync(\n        [FromServices] IPostClientInfoAh handler,\n        [FromBody] InfoSm infoSm,\n        CancellationToken cancellationToken)\n    {\n        return handler.ExecuteAsync(infoSm, cancellationToken);\n    }\n}\n```\n\n## License\n[MIT](https://github.com/a-postx/Delobytes.AspNetCore.Infrastructure/blob/master/LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-postx%2Fdelobytes.aspnetcore.infrastructure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa-postx%2Fdelobytes.aspnetcore.infrastructure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-postx%2Fdelobytes.aspnetcore.infrastructure/lists"}