{"id":24997849,"url":"https://github.com/matheushoske/hoskes.userauthentication.razorlib","last_synced_at":"2026-04-18T06:37:12.518Z","repository":{"id":275638228,"uuid":"926699036","full_name":"matheushoske/Hoskes.UserAuthentication.RazorLib","owner":"matheushoske","description":"The Authentication Razor Class Library is a reusable component for ASP.NET Core applications, providing essential authentication and authorization features. It includes user login, logout, account creation, and a basic profile page, all integrated with Entity Framework Core for efficient data management.","archived":false,"fork":false,"pushed_at":"2025-02-03T18:34:15.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-03T19:33:41.527Z","etag":null,"topics":["authentication","dotnet","efcore","library","razor-pages","reusable"],"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/matheushoske.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":"2025-02-03T17:58:27.000Z","updated_at":"2025-02-03T18:38:02.000Z","dependencies_parsed_at":"2025-02-03T19:33:57.979Z","dependency_job_id":"ac45fd1e-1fbd-4012-a4d8-72ddb5388932","html_url":"https://github.com/matheushoske/Hoskes.UserAuthentication.RazorLib","commit_stats":null,"previous_names":["matheushoske/hoskes.userauthentication.razorlib"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matheushoske%2FHoskes.UserAuthentication.RazorLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matheushoske%2FHoskes.UserAuthentication.RazorLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matheushoske%2FHoskes.UserAuthentication.RazorLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matheushoske%2FHoskes.UserAuthentication.RazorLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matheushoske","download_url":"https://codeload.github.com/matheushoske/Hoskes.UserAuthentication.RazorLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246209601,"owners_count":20741072,"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":["authentication","dotnet","efcore","library","razor-pages","reusable"],"created_at":"2025-02-04T17:25:59.812Z","updated_at":"2026-04-18T06:37:12.479Z","avatar_url":"https://github.com/matheushoske.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Authentication Razor Class Library\n\nThis repository provides a Razor Class Library (RCL) designed to streamline authentication and authorization processes in ASP.NET Core applications. It offers reusable components for user login, logout, account creation, and a basic profile page, all integrated with Entity Framework Core (EF Core) for data management.\n\n## Features\n\n- **User Login:** Allows users to authenticate using their email and password.\n- **User Logout:** Enables users to securely sign out of the application.\n- **Account Creation:** Provides functionality for new users to register by creating an account.\n- **Profile Page:** Offers a basic profile page where users can view and manage their account information.\n- **Entity Framework Core Integration:** Utilizes EF Core for efficient data handling and storage.\n\n## Implementation Details\n\nThe library is structured to be easily integrated into any ASP.NET Core project. It includes Razor Pages for the aforementioned features and employs EF Core for database operations.\n\n**1. User Login:**\n\nThe login functionality is implemented using a Razor Page that accepts the user's email and password, validates the credentials, and establishes an authentication cookie upon successful login.\n\n**2. User Logout:**\n\nA Razor Page handles user logout by clearing the authentication cookie, effectively signing the user out of the application.\n\n**3. Account Creation:**\n\nThe account creation feature is provided through a Razor Page that collects user details, validates the input, and creates a new user record in the database using EF Core.\n\n**4. Profile Page:**\n\nA basic profile page is available where authenticated users can view their account information.\n\n**5. Entity Framework Core Integration:**\n\nEF Core is used for data operations, ensuring efficient and scalable database interactions.\n\n## Integration Guide\n\nTo integrate this Razor Class Library into your ASP.NET Core project, follow these steps:\n\n**1. Add Project Reference:**\n\nIn your main project, add a reference to the Razor Class Library:\n\n- Right-click on the **Dependencies** node in your main project.\n- Select **Add Project Reference**.\n- Choose the Razor Class Library project and click **OK**.\n\n**2. Configure Services:**\n\nIn your `Startup.cs` or `Program.cs`, add the Razor Class Library as an application part:\n\n```csharp\nservices.AddRazorPages()\n        .AddApplicationPart(typeof(Hoskes.UserAuthorization.Pages.LoginAccountModel).Assembly);\n```\n\n**3. Configure EF Core:**\n\nAlso in your `Startup.cs` or `Program.cs`, add the DBContext injection based on your preferred database (In this example we will be using Mysql):\n\nImportant: The library \"Microsoft.EntityFrameworkCore\" will be necessary for this step\nIf you're using Mysql, \"MySql.EntityFrameworkCore\" will be also necessary\n\n```csharp\nbuilder.Services.AddDbContext\u003cHoskesAuthContext\u003e(options =\u003e\n    options.UseMySQL(builder.Configuration.GetConnectionString(\"HoskesAuthContext\") ?? throw new InvalidOperationException(\"Connection string 'HoskesAuthContext' not found.\")));\n```\n**4. Configure Connection String:**\nIn your appsettings.json add your Connection String with the following structure\n\n```json\n\"ConnectionStrings\": {\n\t\"HoskesAuthContext\": \"Server=127.0.0.1;Database=dbName;Uid=dbUsername;Pwd=dbPassword;\"\n}\n```\n\n**5. Configure Authentication:**\n\nEnsure that authentication services are configured in your main project:\n\n```csharp\nservices.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)\n        .AddCookie(options =\u003e\n        {\n            options.LoginPath = \"/LoginAccount\";\n            options.LogoutPath = \"/Logout\";\n        });\n```\n\n**6. Apply Migrations:**\n\nThe Razor Class Library includes an EF Core Context, apply it to your database:\n\n- Open the Development console.\n- Run the following commands:\n\n  ```\n  dotnet package add Microsoft.EntityFrameworkCore.Tools\n  dotnet ef migrations add Migration1\n  dotnet ef database update\n  ```\n\n**7. Access Pages:**\n\nYou can now access the following pages provided by the Razor Class Library:\n\n- **Login:** `/LoginAccount`\n- **Logout:** `/Logout`\n- **Register:** `/CreateAccount`\n- **Profile:** `/Profile`\n\n## Additional Resources\n\nFor more detailed information on implementing authentication and authorization in ASP.NET Core, refer to the official Microsoft documentation:\n\n- [Introduction to Identity on ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-9.0)\n- [Scaffold Identity in ASP.NET Core projects](https://learn.microsoft.com/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-9.0)\n\nBy integrating this Razor Class Library, you can efficiently manage user authentication and authorization in your ASP.NET Core applications, leveraging reusable components and EF Core for data management.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatheushoske%2Fhoskes.userauthentication.razorlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatheushoske%2Fhoskes.userauthentication.razorlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatheushoske%2Fhoskes.userauthentication.razorlib/lists"}