{"id":26711661,"url":"https://github.com/swisslife-oss/bewit","last_synced_at":"2025-04-13T19:51:07.654Z","repository":{"id":46600315,"uuid":"300537929","full_name":"SwissLife-OSS/bewit","owner":"SwissLife-OSS","description":"Security without cookies or tokens","archived":false,"fork":false,"pushed_at":"2023-02-10T14:09:24.000Z","size":1095,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-27T05:21:30.967Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/SwissLife-OSS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2020-10-02T07:36:37.000Z","updated_at":"2023-10-07T23:34:44.000Z","dependencies_parsed_at":"2024-10-20T11:54:28.873Z","dependency_job_id":null,"html_url":"https://github.com/SwissLife-OSS/bewit","commit_stats":{"total_commits":19,"total_committers":5,"mean_commits":3.8,"dds":0.631578947368421,"last_synced_commit":"8e9dd0c23789ea06897e755d099b03d2509a973c"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":"SwissLife-OSS/template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwissLife-OSS%2Fbewit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwissLife-OSS%2Fbewit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwissLife-OSS%2Fbewit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwissLife-OSS%2Fbewit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SwissLife-OSS","download_url":"https://codeload.github.com/SwissLife-OSS/bewit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248773761,"owners_count":21159517,"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":[],"created_at":"2025-03-27T10:30:08.832Z","updated_at":"2025-04-13T19:51:07.630Z","avatar_url":"https://github.com/SwissLife-OSS.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Bewit is an authentication scheme alternative to cookies and bearer tokens.**\n\nBewit enables you to provide authentication in use cases where cookies and authentication headers can not be used. With support for both stateful and stateless authentication, Bewit is a practical solution for many scenarii, including file downloads and temporary or single-use links.\n\n## Getting Started\n\nWe've prepared a simple example of how to use Bewit to provide stateless secure file downloads for a HotChocolate Server.\nIn this scenario, a HotChocolate server will be used to generate secure links. These links can then be used to download content from an Asp.Net MVC Server without cookies or authentication headers.\n\n### Install\n\nYou will need the following package for your HotChocolate Server:\n\n```bash\ndotnet add package Bewit.Extensions.HotChocolate\n```\n\nOn your MVC Server, add the following package:\n\n```bash\ndotnet add package Bewit.Extensions.Mvc\n```\n\n### HotChocolate Server\n\nFirst create a simple HotChocolate API with the following Schema:\n\n```csharp\nconst string mvcApiUrl = \"http://localhost:5000\"; //your mvc api url here\n\nISchema schema = SchemaBuilder.New()\n    .SetOptions(new SchemaOptions\n    {\n        StrictValidation = false //because we don't have a QueryType in this example\n    })\n    .AddMutationType(\n        new ObjectType(\n            d =\u003e\n            {\n                d.Name(\"Mutation\");\n                d.Field(\"RequestAccessUrl\")\n                    .Type\u003cNonNullType\u003cStringType\u003e\u003e()\n                    .Resolver(ctx =\u003e $\"{mvcApiUrl}/api/file/123\")\n                    .UseBewitUrlProtection();\n            }))\n    .Create();\n```\n\nYou'll also need to register some things in the service container:\n\n```csharp\nservices.AddBewitGeneration\u003cstring\u003e(\n    new BewitOptions\n    {\n        Secret = \"my encryption key\",\n        TokenDuration = TimeSpan.FromMinutes(1) //lifespan of the generated url\n    },\n    builder =\u003e builder.UseHmacSha256Encryption()\n);\n```\n\n### MVC Server\n\nCreate a simple Asp.Net MVC Server with the following Controller:\n\n```csharp\n    [Route(\"api/[controller]\")]\n    [ApiController]\n    public class FileController: Controller\n    {\n        [HttpGet(\"{id}\")]\n        [BewitUrlAuthorization]\n        public FileResult GetFile(string id)\n        {\n            return File(/* your file here*/);\n        }\n    }\n```\n\nYou'll also need to register some things in the service container:\n\n```csharp\nservices.AddBewitUrlAuthorizationFilter(\n    new BewitOptions\n    {\n        Secret = \"my encryption key\"\n    },\n    builder =\u003e builder\n        .UseHmacSha256Encryption()\n    );\n```\n\n### Use\n\nYou can now generate secure download urls by calling your mutation:\n\n```graphql\nmutation foo {\n  requestAccessUrl\n}\n```\n\n## Features\n\n### Generating secured Links\n\n- [x] Vanilla (no overhead)\n- [x] HotChocolate integration\n- [ ] graphql-dotnet integration\n\n### Authentication\n\n- [x] Asp.Net MVC\n\n### Persistance (for Stateful authentication)\n\n- [x] MongoDb\n- [ ] Sql Server\n- [ ] Azure Blob Storage\n- [ ] PostgresSQL\n\n## Community\n\nThis project has adopted the code of conduct defined by the [Contributor Covenant](https://contributor-covenant.org/)\nto clarify expected behavior in our community. For more information, see the [Swiss Life OSS Code of Conduct](https://swisslife-oss.github.io/coc).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswisslife-oss%2Fbewit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswisslife-oss%2Fbewit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswisslife-oss%2Fbewit/lists"}