{"id":22352951,"url":"https://github.com/fschick/authentication.onetimetoken","last_synced_at":"2025-10-14T21:31:07.760Z","repository":{"id":63719769,"uuid":"570153721","full_name":"fschick/Authentication.OneTimeToken","owner":"fschick","description":"ASP.NET Core authentication scheme for one-time access tokens to support file download via direct link for protected resources","archived":false,"fork":false,"pushed_at":"2023-06-17T04:37:19.000Z","size":41,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-11T07:00:01.299Z","etag":null,"topics":["asp-net-core","authentication","authorization","csharp","token"],"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/fschick.png","metadata":{"files":{"readme":"README.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-24T13:07:48.000Z","updated_at":"2025-08-23T22:13:27.000Z","dependencies_parsed_at":"2024-12-04T12:32:50.175Z","dependency_job_id":"a6c8a79a-b2c1-4487-8bbc-ea55debe0650","html_url":"https://github.com/fschick/Authentication.OneTimeToken","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/fschick/Authentication.OneTimeToken","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschick%2FAuthentication.OneTimeToken","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschick%2FAuthentication.OneTimeToken/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschick%2FAuthentication.OneTimeToken/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschick%2FAuthentication.OneTimeToken/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fschick","download_url":"https://codeload.github.com/fschick/Authentication.OneTimeToken/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschick%2FAuthentication.OneTimeToken/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279021373,"owners_count":26087022,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["asp-net-core","authentication","authorization","csharp","token"],"created_at":"2024-12-04T12:31:55.911Z","updated_at":"2025-10-14T21:31:07.460Z","avatar_url":"https://github.com/fschick.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ASP.NET One-Time Token Authentication\nProvides an authentication scheme for one-time access tokens to support file download via direct link for protected resources\n## Frameworks supported\n- ASP.NET Core 6.0\n- ASP.NET Core 7.0\n## Demo\nA demo application can be found in folder `FS.Authentication.OneTimeToken.Demo`\n## Installation\nInstall from NuGet package\n```powershell\nInstall-Package Schick.Authentication.OneTimeToken\n```\n## Getting Started\nAdd `Authorize` attribute with one-time token authentication scheme to controller / minimal API\n```csharp\n// Authenticate via one-time access token.\n[Authorize(AuthenticationSchemes = OneTimeTokenDefaults.AuthenticationScheme)]\ninternal static string RequireOneTimeTokenAuthentication()\n\t=\u003e \"Hello, you are authenticated\";\n```\nRegister one-time access token authorization scheme\n```c#\n// Add default authentication, e.g. NTLM/Windows, JWT, ...\nbuilder.Services.AddAuthentication(...);\n...\n// Add one-time access token authentication.\nbuilder.Services.AddOneTimeTokenAuthentication(config =\u003e { /* your options here */ });\n```\nTokens can be generated via `IOneTimeTokenService.CreateToken`\n```c#\n\u003cserviceProvider\u003e.GetRequiredService\u003cIOneTimeTokenService\u003e().CreateToken(/* claims */);\n```\n## Full Sample\n```c#\nusing FS.Authentication.OneTimeToken.Abstractions.Interfaces;\nusing FS.Authentication.OneTimeToken.Abstractions.Models;\nusing FS.Authentication.OneTimeToken.Extensions;\nusing Microsoft.AspNetCore.Authentication.Negotiate;\nusing Microsoft.AspNetCore.Authorization;\nusing Microsoft.AspNetCore.Builder;\nusing Microsoft.AspNetCore.Http;\nusing Microsoft.AspNetCore.Mvc;\nusing Microsoft.Extensions.DependencyInjection;\nusing Swashbuckle.AspNetCore.Annotations;\nusing System.ComponentModel;\n\nnamespace FS.Authentication.OneTimeToken.Demo;\n\npublic class Program\n{\n    public const string DEFAULT_ROLE = \"DefaultUser\";\n\n    // Authenticate / authorize via default authentication, e.g. NTLM/Windows, JWT, ...\n    [Authorize]\n    internal static string GetOneTimeToken(HttpContext httpContext, [FromQuery][DefaultValue(DEFAULT_ROLE)][SwaggerParameter(Required = false)] string role)\n        =\u003e httpContext.RequestServices.GetRequiredService\u003cIOneTimeTokenService\u003e().CreateToken(role);\n\n    // Authenticate via one-time access token.\n    [Authorize(AuthenticationSchemes = OneTimeTokenDefaults.AuthenticationScheme)]\n    internal static string RequireOneTimeTokenAuthentication([FromQuery] string accessToken)\n        =\u003e \"Hello, you are authenticated\";\n\n    // Authenticate /authorize via one-time access token.\n    [Authorize(AuthenticationSchemes = OneTimeTokenDefaults.AuthenticationScheme, Roles = DEFAULT_ROLE)]\n    internal static string RequireOneTimeTokenAuthorization([FromQuery] string accessToken)\n        =\u003e \"Hello, you are authorized\";\n\n    public static void Main(string[] args)\n    {\n        var builder = WebApplication.CreateBuilder(args);\n\n        // Add default authentication, e.g. NTLM/Windows, JWT, ...\n        builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();\n        builder.Services.AddAuthorization();\n\n        // Add one-time access token authentication.\n        builder.Services.AddOneTimeTokenAuthentication(config =\u003e { /* your options here */ });\n\n        AddSwagger(builder);\n\n        var app = builder.Build();\n\n        app.UseAuthentication();\n        app.UseAuthorization();\n\n        app.MapGet(nameof(GetOneTimeToken), GetOneTimeToken);\n        app.MapGet(nameof(RequireOneTimeTokenAuthentication), RequireOneTimeTokenAuthentication);\n        app.MapGet(nameof(RequireOneTimeTokenAuthorization), RequireOneTimeTokenAuthorization);\n\n        AddSwaggerUi(app);\n\n        app.Run();\n    }\n\n    private static void AddSwagger(WebApplicationBuilder builder)\n    {\n        builder.Services.AddEndpointsApiExplorer();\n        builder.Services.AddSwaggerGen(config =\u003e config.EnableAnnotations());\n    }\n\n    private static void AddSwaggerUi(WebApplication app)\n    {\n        app.UseSwagger();\n        app.UseSwaggerUI(options =\u003e\n        {\n            options.DisplayRequestDuration();\n            options.EnableDeepLinking();\n            options.EnableTryItOutByDefault();\n            options.ConfigObject.AdditionalItems.Add(\"requestSnippetsEnabled\", true);\n        });\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffschick%2Fauthentication.onetimetoken","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffschick%2Fauthentication.onetimetoken","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffschick%2Fauthentication.onetimetoken/lists"}