{"id":19541447,"url":"https://github.com/genesisblock3301/role_based_authentication_golang","last_synced_at":"2025-10-05T08:18:14.032Z","repository":{"id":200171750,"uuid":"704507223","full_name":"GenesisBlock3301/role_based_authentication_golang","owner":"GenesisBlock3301","description":"This GoLang application implements a role-based authentication system, providing secure access control to various resources. It encompasses features like Google OAuth, JWT token authentication, and email verifications for user management.","archived":false,"fork":false,"pushed_at":"2024-03-17T04:52:48.000Z","size":30027,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-26T05:18:47.383Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GenesisBlock3301.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":"2023-10-13T12:06:58.000Z","updated_at":"2023-10-31T06:39:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"d6c500f3-df96-4587-9bd3-673339dd1d35","html_url":"https://github.com/GenesisBlock3301/role_based_authentication_golang","commit_stats":null,"previous_names":["genesisblock3301/role_based_access_boilerplate_go"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/GenesisBlock3301/role_based_authentication_golang","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GenesisBlock3301%2Frole_based_authentication_golang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GenesisBlock3301%2Frole_based_authentication_golang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GenesisBlock3301%2Frole_based_authentication_golang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GenesisBlock3301%2Frole_based_authentication_golang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GenesisBlock3301","download_url":"https://codeload.github.com/GenesisBlock3301/role_based_authentication_golang/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GenesisBlock3301%2Frole_based_authentication_golang/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278425743,"owners_count":25984761,"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-05T02:00:06.059Z","response_time":54,"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":[],"created_at":"2024-11-11T03:10:32.165Z","updated_at":"2025-10-05T08:18:14.014Z","avatar_url":"https://github.com/GenesisBlock3301.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Role-Based Authentication in GoLang Application\n\n## Overview\nThis GoLang application implements a role-based authentication system, providing secure access control to various resources. It encompasses features like Google OAuth, JWT token authentication, and email verifications for user management.\n## Table Structure\nThe application's database schema includes the following tables:\n\n**User:** Stores user information including username, email, password hash, and associated roles.\n**Role:** Contains roles with corresponding permissions.\u003cbr\u003e\n**Permission:** Lists specific actions that can be performed within the application.\n\n## Authentication Methods\n**1. Google OAuth**\n   This application integrates with Google OAuth for seamless user authentication. Users can log in using their Google credentials, which are then used to create or update their profile in the application's database.\n\n**2. JWT Token Authentication**\n   JWT tokens are employed for secure communication between the client and the server. After successful authentication, a JWT token is generated and provided to the client, which is then included in subsequent requests for authorization.\n\n**3. Email Verification**\n   To ensure a valid email address, users receive a verification link upon registration. Clicking this link confirms the email address and activates the account.\n\n## Role-Based Access Control (RBAC)\nRoles play a central role in defining what actions a user can perform within the application. Each role is associated with specific permissions, providing granular control over the features and resources accessible to users.\n\n### Project Structure:\n```\nrole_based_access_boilerplate_go/\n├── cmd/\n│   └── main.go\n├── internal/\n│   ├── configurations/\n│   │     ├── db/\n│   │     │   └── config.go\n│   │     │   └── models.go\n│   ├── controller/\n│   │     ├── user/\n│   │     │     └── user-controller.go\n│   │     ├── role/\n│   │     │     └── roles-controller.go\n│   │     └── router.go\n│   ├── middleware/\n│   │    └── auth-middleware.go\n│   ├── routes/\n│   │     ├── user/\n│   │     │     └── user-router.go\n│   │     ├── role/\n│   │     │     └── roles-router.go\n│   │     └── router.go\n│   ├── serializers/\n│   │    └── user-serializers.go\n│   ├── service/\n│   │     ├── user/\n│   │     │     └── user-service.go\n│   │     ├── role/\n│   │     │     └── roles-service.go\n├── test/\n│   └── my_service_test.go\n└── README.md\n```\n\n## Explanation:\n**/cmd:** Contains the main entry point for your application.\n**/internal:** Contains internal packages, including database operations and data models. \n  - **/configurations**: Houses API handlers for user, role, and permission management.\n  - **/controllers**: \n  - **/middlewares**:\n  - **/routes**:\n  - **/schemas**:\n  - **/serializers**:\n  - **/services**\n  - **/utils**:\nREADME.md: This file, providing an overview of the project.\n\n## Getting Started\n1. Clone the repository.\n2. Initialize the database using the provided SQL script in /scripts.\n3. Customize the authentication methods and API handlers according to your requirements.\n4. Run the application using go run cmd/your-app/main.go.\n\n## Creating Project: \n- Open project folder\n- Command: `go mod init`\n\n## Design database model \u0026 making operations:\n- Follow GORM orm documentation. \n\n## How JWT Token Generate:\n\n---\n1. Authenticated User login using credentials (username, password).\n2. Verify credential of users(Username \u0026 password).\n3. Then generate token and enter Generate token function.\n4. Add JWT claims. For example: `Authorization`, `exp`, `user_id` etc.\n5. Using these claims generate token with secret key.\n\n\n## How to make JWT token validation when I make call with this Token(middleware):\n\n---\n1. Firstly token parse which is provided by frontend and find exact token.\n2. Then check token validation, if valid then move forward.\n3. From this token, after decoding we can get userID.\n\n\n## How does Register email verification work:\n\n---\n1. Firstly user apply for information registration.\n2. Then make email template with **verification link** and send it on behalf of system to client.\n3. Verification link containing unique token.\n4. Click on that link \u0026 activate this user \u0026 redirect to home page.\n\n## How generate OTP work \u0026 when we should use OTP:\n\n---\nGenerally OTP generated after enter login credentials, here we use One time Generated password,\nlifetime 30 sec.\n1. Generated OTP from gotp module.\n2. then send this OTP code to email.\n3. Verify OTP code to enter into another gotp module.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenesisblock3301%2Frole_based_authentication_golang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenesisblock3301%2Frole_based_authentication_golang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenesisblock3301%2Frole_based_authentication_golang/lists"}