{"id":17520784,"url":"https://github.com/9ssi7/sudo","last_synced_at":"2025-03-28T23:25:43.731Z","repository":{"id":225386631,"uuid":"765844275","full_name":"9ssi7/sudo","owner":"9ssi7","description":"traditional sudo mode feature to your golang backend/microservice","archived":false,"fork":false,"pushed_at":"2024-03-01T19:08:14.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T15:56:15.157Z","etag":null,"topics":["2fa-security","golang","security","sudo"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/9ssi7/sudo","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/9ssi7.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}},"created_at":"2024-03-01T18:22:30.000Z","updated_at":"2024-03-01T19:05:45.000Z","dependencies_parsed_at":"2024-03-01T20:27:10.142Z","dependency_job_id":"460c0406-853d-4a45-bd2d-2c265a7096c8","html_url":"https://github.com/9ssi7/sudo","commit_stats":null,"previous_names":["9ssi7/sudo"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9ssi7%2Fsudo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9ssi7%2Fsudo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9ssi7%2Fsudo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/9ssi7%2Fsudo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/9ssi7","download_url":"https://codeload.github.com/9ssi7/sudo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246114124,"owners_count":20725576,"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":["2fa-security","golang","security","sudo"],"created_at":"2024-10-20T11:24:36.693Z","updated_at":"2025-03-28T23:25:43.712Z","avatar_url":"https://github.com/9ssi7.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"### sudo\n\nThe `sudo` package provides functionality for managing sudo-like operations, including user verification, token generation, and verification code validation.\n\n### Installation\n\nTo install the `sudo` package, use the following `go get` command:\n\n```bash\ngo get -u github.com/9ssi7/sudo\n```\n\n### Usage\n\nImport the `sudo` package into your code:\n\n```go\nimport \"github.com/9ssi7/sudo\"\n```\n\n### Configuration\n\nCreate a `sudo.Config` instance to configure the `sudo` service:\n\n```go\nconfig := sudo.Config{\n    Redis:        // Your Redis service instance,\n    NotifySender: // Your NotifySender function,\n    Expire:       // Optional: Set the expiration time for verification codes. Default is 5 minutes.\n}\n\nsudoService := sudo.New(config)\n```\n\n### Service Methods\n\n#### `Check`\n\nCheck verifies the validity of a given token.\n\n```go\ncmd := sudo.CheckCommand{\n    UserId:   \"user123\",\n    DeviceId: \"device456\",\n    Token:    \"your_token\",\n}\n\nerr := sudoService.Check(context.Background(), cmd)\n```\n\n#### `Start`\n\nStart initiates the sudo process by generating a verification code and notifying the user.\n\n```go\ncmd := sudo.StartCommand{\n    UserId:   \"user123\",\n    DeviceId: \"device456\",\n    Phone:    \"+1234567890\",\n    Email:    \"user@example.com\",\n    Locale:   \"en_US\",\n}\n\ntoken, err := sudoService.Start(context.Background(), cmd)\n```\n\n#### `Verify`\n\nVerify validates a user's input against the generated verification code.\n\n```go\ncmd := sudo.VerifyCommand{\n    UserId:      \"user123\",\n    DeviceId:    \"device456\",\n    VerifyToken: \"generated_verify_token\",\n    Code:        \"user_input_code\",\n}\n\naccessToken, err := sudoService.Verify(context.Background(), cmd)\n```\n\n### Notifications\n\nThe package requires a notification sender function (`NotifySender`) to notify users during the sudo process.\n\n```go\nnotifyFunc := func(cmd sudo.NotifyCommand) {\n    // Implement your notification logic here\n}\n\nconfig.NotifySender = notifyFunc\n```\n\n### Error Messages\n\nThe package provides the following error messages:\n\n- `sudo_redis_fetch_failed`\n- `sudo_redis_set_failed`\n- `sudo_json_marshal_failed`\n- `sudo_not_found`\n- `sudo_invalid_token`\n- `sudo_invalid_code`\n- `sudo_expired_code`\n- `sudo_exceed_try_count`\n- `sudo_unknown`\n- `sudo_verify_started`\n\n### Example\n\nFor a complete working examples, refer to the [recipes](github.com/9ssi7/recipes) repository.\n\n### License\n\nThis package is licensed under the [Apache-2.0 License](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F9ssi7%2Fsudo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F9ssi7%2Fsudo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F9ssi7%2Fsudo/lists"}