{"id":22694974,"url":"https://github.com/aguafrommars/dynamicauthproviders","last_synced_at":"2025-05-09T02:59:56.257Z","repository":{"id":37879024,"uuid":"160871725","full_name":"Aguafrommars/DynamicAuthProviders","owner":"Aguafrommars","description":"Store and manage Microsoft.AspNetCore.Authentication providers dynamicaly","archived":false,"fork":false,"pushed_at":"2025-05-07T06:15:34.000Z","size":2408,"stargazers_count":56,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-09T02:59:50.296Z","etag":null,"topics":["aspnetcore","authentication","security"],"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/Aguafrommars.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"aguacongas","liberapay":"aguacongas","issuehunt":"aguacongas"}},"created_at":"2018-12-07T20:22:10.000Z","updated_at":"2025-05-07T06:15:38.000Z","dependencies_parsed_at":"2023-10-17T07:43:41.862Z","dependency_job_id":"88ed8e45-baa2-4f39-a6d4-2662e732be43","html_url":"https://github.com/Aguafrommars/DynamicAuthProviders","commit_stats":null,"previous_names":["aguacongas/dymamicauthproviders"],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aguafrommars%2FDynamicAuthProviders","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aguafrommars%2FDynamicAuthProviders/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aguafrommars%2FDynamicAuthProviders/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aguafrommars%2FDynamicAuthProviders/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aguafrommars","download_url":"https://codeload.github.com/Aguafrommars/DynamicAuthProviders/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253181418,"owners_count":21866991,"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":["aspnetcore","authentication","security"],"created_at":"2024-12-10T03:10:38.492Z","updated_at":"2025-05-09T02:59:56.242Z","avatar_url":"https://github.com/Aguafrommars.png","language":"C#","funding_links":["https://github.com/sponsors/aguacongas","https://liberapay.com/aguacongas","https://issuehunt.io/r/aguacongas"],"categories":[],"sub_categories":[],"readme":"# DynamicAuthProviders\n\nStore and manage Microsoft.AspNetCore.Authentication providers dynamicaly.\n\n[![Build status](https://ci.appveyor.com/api/projects/status/c92qtam52ughrtv1?svg=true)](https://ci.appveyor.com/project/aguacongas/dymamicauthproviders)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=aguacongas_DymamicAuthProviders\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=aguacongas_DymamicAuthProviders)\n[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/3160/badge)](https://bestpractices.coreinfrastructure.org/projects/3160)\n\nNuget packages\n--------------\n|Dynamic Provider|EntityFramework Store|Redis Store|RavenDB Store|Tests Suite|\n|:------:|:------:|:------:|:------:|:------:|\n|[![][Aguacongas.AspNetCore.Authentication-badge]][Aguacongas.AspNetCore.Authentication-nuget]|[![][Aguacongas.AspNetCore.Authentication.EntityFramework-badge]][Aguacongas.AspNetCore.Authentication.EntityFramework-nuget]|[![][Aguacongas.AspNetCore.Authentication.Redis-badge]][Aguacongas.AspNetCore.Authentication.Redis-nuget]|[![][Aguacongas.AspNetCore.Authentication.RavenDB-badge]][Aguacongas.AspNetCore.Authentication.RavenDB-nuget]|[![][Aguacongas.AspNetCore.Authentication.TestBase-badge]][Aguacongas.AspNetCore.Authentication.TestBase-nuget]|\n|[![][Aguacongas.AspNetCore.Authentication-downloadbadge]][Aguacongas.AspNetCore.Authentication-nuget]|[![][Aguacongas.AspNetCore.Authentication.EntityFramework-downloadbadge]][Aguacongas.AspNetCore.Authentication.EntityFramework-nuget]|[![][Aguacongas.AspNetCore.Authentication.Redis-downloadbadge]][Aguacongas.AspNetCore.Authentication.Redis-nuget]|[![][Aguacongas.AspNetCore.Authentication.RavenDB-downloadbadge]][Aguacongas.AspNetCore.Authentication.RavenDB-nuget]|[![][Aguacongas.AspNetCore.Authentication.TestBase-downloadbadge]][Aguacongas.AspNetCore.Authentication.TestBase-nuget]|  \n\n[Aguacongas.AspNetCore.Authentication-badge]: https://img.shields.io/nuget/v/Aguacongas.AspNetCore.Authentication.svg\n[Aguacongas.AspNetCore.Authentication-downloadbadge]: https://img.shields.io/nuget/dt/Aguacongas.AspNetCore.Authentication.svg\n[Aguacongas.AspNetCore.Authentication-nuget]: https://www.nuget.org/packages/Aguacongas.AspNetCore.Authentication/\n\n[Aguacongas.AspNetCore.Authentication.EntityFramework-badge]: https://img.shields.io/nuget/v/Aguacongas.AspNetCore.Authentication.EntityFramework.svg\n[Aguacongas.AspNetCore.Authentication.EntityFramework-downloadbadge]: https://img.shields.io/nuget/dt/Aguacongas.AspNetCore.Authentication.EntityFramework.svg\n[Aguacongas.AspNetCore.Authentication.EntityFramework-nuget]: https://www.nuget.org/packages/Aguacongas.AspNetCore.Authentication.EntityFramework/\n\n[Aguacongas.AspNetCore.Authentication.Redis-badge]: https://img.shields.io/nuget/v/Aguacongas.AspNetCore.Authentication.Redis.svg\n[Aguacongas.AspNetCore.Authentication.Redis-downloadbadge]: https://img.shields.io/nuget/dt/Aguacongas.AspNetCore.Authentication.Redis.svg\n[Aguacongas.AspNetCore.Authentication.Redis-nuget]: https://www.nuget.org/packages/Aguacongas.AspNetCore.Authentication.Redis/\n\n[Aguacongas.AspNetCore.Authentication.RavenDB-badge]: https://img.shields.io/nuget/v/Aguacongas.AspNetCore.Authentication.RavenDB.svg\n[Aguacongas.AspNetCore.Authentication.RavenDB-downloadbadge]: https://img.shields.io/nuget/dt/Aguacongas.AspNetCore.Authentication.RavenDB.svg\n[Aguacongas.AspNetCore.Authentication.RavenDB-nuget]: https://www.nuget.org/packages/Aguacongas.AspNetCore.Authentication.RavenDB/\n\n[Aguacongas.AspNetCore.Authentication.TestBase-badge]: https://img.shields.io/nuget/v/Aguacongas.AspNetCore.Authentication.TestBase.svg\n[Aguacongas.AspNetCore.Authentication.TestBase-downloadbadge]: https://img.shields.io/nuget/dt/Aguacongas.AspNetCore.Authentication.TestBase.svg\n[Aguacongas.AspNetCore.Authentication.TestBase-nuget]: https://www.nuget.org/packages/Aguacongas.AspNetCore.Authentication.TestBase/\n\n## Setup\n\nIn your Startup `ConfigureServices` method, add the following:\n\n``` csharp\n/** Add dynamic management **/\n\n// Add the context to store schemes configurations.\n// The context can be any kind of DbContext having a DbSet\u003cTSchemeDefinition\u003e\n// where TSchemeDefinition is of type SchemeDefinition or derived.\nservices.AddDbContext\u003cSchemeDbContext\u003e(options =\u003e\n{\n    options.UseSqlServer(Configuration.GetConnectionString(\"Default\"));\n}); \n\n// Add authentication\nvar authBuilder = services\n    .AddAuthentication();\n\n// Add the magic\nvar dynamicBuilder = authBuilder\n    .AddDynamic\u003cSchemeDefinition\u003e()\n    .AddEntityFrameworkStore\u003cSchemeDbContext\u003e();\n\n// Add providers managed dynamically\ndynamicBuilder.AddGoogle()\n    .AddOAuth(\"Github\", \"Github\", options =\u003e\n    {\n        // You can define default configuration for managed handlers.\n        options.AuthorizationEndpoint = \"https://github.com/login/oauth/authorize\";\n        options.TokenEndpoint = \"https://github.com/login/oauth/access_token\";\n        options.UserInformationEndpoint = \"https://api.github.com/user\";\n        options.ClaimsIssuer = \"OAuth2-Github\";\n        // Retrieving user information is unique to each provider.\n        options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, \"id\");\n        options.ClaimActions.MapJsonKey(ClaimTypes.Name, \"login\");\n        options.ClaimActions.MapJsonKey(\"urn:github:name\", \"name\");\n        options.ClaimActions.MapJsonKey(ClaimTypes.Email, \"email\", ClaimValueTypes.Email);\n        options.ClaimActions.MapJsonKey(\"urn:github:url\", \"url\");\n        options.Events = new OAuthEvents\n        {\n            OnCreatingTicket = async context =\u003e\n            {\n                // Get the GitHub user\n                var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint);\n                request.Headers.Authorization = new AuthenticationHeaderValue(\"Bearer\", context.AccessToken);\n                request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(\"application/json\"));\n                // A user-agent header is required by GitHub. See (https://developer.github.com/v3/#user-agent-required)\n                request.Headers.UserAgent.Add(new ProductInfoHeaderValue(\"DynamicAuthProviders-sample\", \"1.0.0\"));\n\n                var response = await context.Backchannel.SendAsync(request, context.HttpContext.RequestAborted);\n                var content = await response.Content.ReadAsStringAsync();\n                response.EnsureSuccessStatusCode();\n\n                var user = JObject.Parse(content);\n\n                context.RunClaimActions(user);\n            }\n        };\n    }); \n\n```\n\nAnd in the `Configure` method load the configuration with `LoadDynamicAuthenticationConfiguration` method:\n\n``` csharp\n\n    app.UseHttpsRedirection()\n        .UseStaticFiles()\n        .UseCookiePolicy()\n        .UseAuthentication()\n        .UseMvc(routes =\u003e\n        {\n            routes.MapRoute(\n                name: \"default\",\n                template: \"{controller=Home}/{action=Index}/{id?}\");\n        })\n        // load dynamyc authentication configuration from store\n        .LoadDynamicAuthenticationConfiguration();\n\n```\n\nRead the [wiki](../../wiki) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faguafrommars%2Fdynamicauthproviders","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faguafrommars%2Fdynamicauthproviders","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faguafrommars%2Fdynamicauthproviders/lists"}