{"id":19054776,"url":"https://github.com/fabioluz/go-auth","last_synced_at":"2026-05-07T01:35:06.543Z","repository":{"id":224934434,"uuid":"764633533","full_name":"fabioluz/go-auth","owner":"fabioluz","description":"API with Authentication in Go","archived":false,"fork":false,"pushed_at":"2024-04-22T00:16:19.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-02T11:11:46.565Z","etag":null,"topics":["api","gin-gonic","go","jwt","mongodb"],"latest_commit_sha":null,"homepage":"","language":"Go","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/fabioluz.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":"2024-02-28T12:42:51.000Z","updated_at":"2024-04-22T00:16:22.000Z","dependencies_parsed_at":"2025-01-02T11:10:58.063Z","dependency_job_id":"7361dba2-4ba2-4da2-841f-c1b288a77038","html_url":"https://github.com/fabioluz/go-auth","commit_stats":null,"previous_names":["fabioluz/go-auth"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioluz%2Fgo-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioluz%2Fgo-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioluz%2Fgo-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioluz%2Fgo-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabioluz","download_url":"https://codeload.github.com/fabioluz/go-auth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240110356,"owners_count":19749288,"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":["api","gin-gonic","go","jwt","mongodb"],"created_at":"2024-11-08T23:39:45.276Z","updated_at":"2026-05-07T01:35:01.520Z","avatar_url":"https://github.com/fabioluz.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GO Auth\n\nThis an example of API with authentication in Go. It gives some separation of concerns by organizing the layers into different packages, isolating the capabilities on their own files, and abstracting the dependencies using design patterns. All dependencies are interpreted in the `main.go` file. \n\nLibraries used:\n* Gin for the API.\n* JWT for generating authorization token.\n* MongoDB Client for database connection.\n\nThe application is capable of creating, authorizing, and updating users. All the operations are logged in the database and can be also retrieved in the API.\n\n\nYou can run everything via docker compose.\n\n## Prerequisites\n\n- Docker installed on your machine\n  \n\n## Setting Up the Application\n\nFirstly, you need to create a `.env` file in the root folder containing:\n\n```\nDB_URI=mongodb://appmongo1:27017\nDB_REPLICA_SET=myReplicaSet\nJWT_SECRET=\u003cYOUR_TOKEN_SECRET_HERE\u003e\n```\n\nYou can change the details of `DB_URI` and `DB_REPLICA_SET` as needed.\n\nThen, build the API and MongoDB cluster by running then via docker compose:\n\n```bash\ndocker compose up -d\n```\n\n## Using the application\n\n### Creating an user\n\n```\nPOST http://localhost:8080/users/\n{\n    \"email\": \"test@test.com\",\n    \"password\": \"nicepassword\",\n    \"confirmPassword\": \"nicepassword\",\n    \"name\": \"wow nice name\"\n}\n```\n\n### Authenticating an user\n\n```\nPOST http://localhost:8080/authenticate/\n{\n    \"email\": \"test@test.com\",\n    \"password\": \"nicepassword\"\n}\n```\n\nThis should return the `token` and `id` that you can use to access the API.\n\n### Authorizing an user\n\nAdd an HTTP `Authorization` header with the format `Bearer {token}`\n\n### Fetching logged-in user info\n\n```\nGET http://localhost:8080/me\nHEADER Autorization: Bearer {token}\n```\n\nReturns the details of the logged-in user.\n\n### Fetching user logs\n\n```\nGET http://localhost:8080/users/{id}/logs\nHEADER Authorization: Bearer {token}\n```\n\nReturns the logs for the specified user.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabioluz%2Fgo-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabioluz%2Fgo-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabioluz%2Fgo-auth/lists"}