{"id":15549323,"url":"https://github.com/adityaoberai/jwtauthsample","last_synced_at":"2025-05-05T03:44:07.025Z","repository":{"id":114528597,"uuid":"525961539","full_name":"adityaoberai/JWTAuthSample","owner":"adityaoberai","description":"ASP.NET Web API sample to showcase JWT Token Authentication in .NET 6","archived":false,"fork":false,"pushed_at":"2023-05-31T12:57:22.000Z","size":12,"stargazers_count":33,"open_issues_count":0,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T03:43:58.615Z","etag":null,"topics":["asp-net-web-api","bcrypt","dotnet","dotnet-6","efcore","jwt"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adityaoberai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-08-17T21:38:49.000Z","updated_at":"2025-04-12T04:33:45.000Z","dependencies_parsed_at":"2024-07-23T04:02:52.167Z","dependency_job_id":null,"html_url":"https://github.com/adityaoberai/JWTAuthSample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityaoberai%2FJWTAuthSample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityaoberai%2FJWTAuthSample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityaoberai%2FJWTAuthSample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityaoberai%2FJWTAuthSample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adityaoberai","download_url":"https://codeload.github.com/adityaoberai/JWTAuthSample/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252436240,"owners_count":21747467,"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":["asp-net-web-api","bcrypt","dotnet","dotnet-6","efcore","jwt"],"created_at":"2024-10-02T13:35:03.781Z","updated_at":"2025-05-05T03:44:06.985Z","avatar_url":"https://github.com/adityaoberai.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JWT Authentication .NET Sample\n\n## Description\n\nThe **JWT Authentication .NET Sample** is an **sample ASP.NET Web API** to help understand how role based authentication can be implemented via JWTs in a **.NET 6** application. It utilizes an **InMemory database** using **Entity Framework Core** for storing user data and the **BCrypt** library for encrypting passwords.\n\nThe API has 1 controller:\n\n* **AuthController**: Contains the login, registration, and test APIs\n\n### AuthController\n\nThe `AuthController` contains the login, registration, and test APIs we are using to get and try the JWT token authentication.\n\n* POST `/auth/login`\n\n    * Returns the JWT token along with the user information from the database after the user enters their email and password.\n    * Post Http Request Link: `https://\u003cYOUR-DOMAIN:PORT\u003e//auth/login`\n    * Request Body Example:\n\n        ```json\n        {\n            \"userName\": \"adityaoberai1\",\n            \"password\": \"test123\"\n        }\n        ```\n\n    * Response Example:\n\n        ```json\n        {\n            \"userName\": \"adityaoberai1\",\n            \"name\": \"Aditya\",\n            \"role\": \"Everyone\",\n            \"isActive\": true,\n            \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiYWRpdHlhb2JlcmFpMSIsImdpdmVuX25hbWUiOiJBZGl0eWEiLCJyb2xlIjoiRXZlcnlvbmUiLCJuYmYiOjE2NjA3NzA0NDQsImV4cCI6MTY2MDc3MjI0NCwiaWF0IjoxNjYwNzcwNDQ0fQ.20KEe53MsDeapYk0EkeayfZqmsyPSuVOVBzsHpmFMS4\",\n            \"password\": \"$2a$11$DdJgRS3BKpoo64ap940g9.TsFzharf5PwCn1BH4e/oIBeNf7FKiOe\"\n        }\n        ```\n\n* POST `/auth/register`\n\n    * Adds the user's details to the database and returns the JWT token along with the user information after the user enters their information.\n    * Post Http Request Link: `https://\u003cYOUR-DOMAIN:PORT\u003e/auth/register`\n    * Request Body Example:\n\n        ```json\n        {\n            \"name\": \"Aditya\",\n            \"userName\": \"adityaoberai1\",\n            \"password\": \"test123\",\n            \"role\": \"Everyone\"\n        }\n        ```\n\n    * Response Example:\n\n        ```json\n        {\n            \"userName\": \"adityaoberai1\",\n            \"name\": \"Aditya\",\n            \"role\": \"Everyone\",\n            \"isActive\": true,\n            \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiYWRpdHlhb2JlcmFpMSIsImdpdmVuX25hbWUiOiJBZGl0eWEiLCJyb2xlIjoiRXZlcnlvbmUiLCJuYmYiOjE2NjA3NzAzNjAsImV4cCI6MTY2MDc3MjE2MCwiaWF0IjoxNjYwNzcwMzYwfQ.oCK_udTh83F-OM7yLYK7NBQa8basKTVQpMF3GUYtUtA\",\n            \"password\": \"$2a$11$DdJgRS3BKpoo64ap940g9.TsFzharf5PwCn1BH4e/oIBeNf7FKiOe\"\n        }\n        ```\n\n        *Note: Token returned will be different from the example*\n\n* GET `/auth/test`\n\n    * Returns claims from the JWT sent as the **Bearer token** in the `Authorization` header with **Everyone** role.\n    * Get Http Request Link: `https://\u003cYOUR-DOMAIN:PORT\u003e/auth/test`\n    * Request Header Example:\n\n        `Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiYWRpdHlhb2JlcmFpMSIsImdpdmVuX25hbWUiOiJBZGl0eWEiLCJyb2xlIjoiRXZlcnlvbmUiLCJuYmYiOjE2NjA3NzA0NDQsImV4cCI6MTY2MDc3MjI0NCwiaWF0IjoxNjYwNzcwNDQ0fQ.20KEe53MsDeapYk0EkeayfZqmsyPSuVOVBzsHpmFMS4`\n\n    * Response Example:\n\n        ```json\n        {\n            \"name\": \"adityaoberai1\",\n            \"given_name\": \"Aditya\",\n            \"role\": \"Everyone\",\n            \"nbf\": \"1660770444\",\n            \"exp\": \"1660772244\",\n            \"iat\": \"1660770444\"\n        }\n        ```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadityaoberai%2Fjwtauthsample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadityaoberai%2Fjwtauthsample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadityaoberai%2Fjwtauthsample/lists"}