{"id":15591322,"url":"https://github.com/zhashkevych/auth","last_synced_at":"2025-04-28T10:46:26.733Z","repository":{"id":118975373,"uuid":"250261046","full_name":"zhashkevych/auth","owner":"zhashkevych","description":"Simple HTTP Authentication REST API ready for use in your projects","archived":false,"fork":false,"pushed_at":"2020-03-31T15:31:50.000Z","size":22,"stargazers_count":26,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T15:16:37.801Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/zhashkevych.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":"2020-03-26T13:07:05.000Z","updated_at":"2024-11-24T16:09:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"c9342864-61ed-4287-92fe-b53923d8d143","html_url":"https://github.com/zhashkevych/auth","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/zhashkevych%2Fauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhashkevych%2Fauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhashkevych%2Fauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhashkevych%2Fauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhashkevych","download_url":"https://codeload.github.com/zhashkevych/auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251297947,"owners_count":21566924,"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":[],"created_at":"2024-10-02T23:41:00.024Z","updated_at":"2025-04-28T10:46:26.710Z","avatar_url":"https://github.com/zhashkevych.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTP Authentication Server\n\n## \u003ca href=\"https://medium.com/@zhashkevych/jwt-%D0%B0%D0%B2%D1%82%D0%BE%D1%80%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F-%D0%B4%D0%BB%D1%8F-%D0%B2%D0%B0%D1%88%D0%B5%D0%B3%D0%BE-api-%D0%BD%D0%B0-go-80325de8691b\"\u003eBlog Post\u003c/a\u003e\n\n## Requirements\n- docker \u0026 docker-compose\n\n## Run Project\n\nSet your signing key and hash salt in config file `pkg/config/config.yml` before running server\n\nUse ```make run``` to build and run docker containers with application itself and mongodb instance\n\n## Parse Token\n\nYou can import `github.com/zhashkevych/auth/pkg/parser` into your Go application and user `ParseToken()` to validate and parse token claims.\n\n#### See example at `cmd/example/main.go -username=user -pass=pass`\n\nYou can run example using `go run main.go` but make sure you have golang installed on your machine\n\n## Authentication Middleware Example Using Go/Gin\n\n```golang\nfunc Middleware(c *gin.Context) {\n\tauthHeader := c.GetHeader(\"Authorization\")\n\tif authHeader == \"\" {\n\t\tc.AbortWithStatus(http.StatusUnauthorized)\n\t\treturn\n\t}\n\n\theaderParts := strings.Split(authHeader, \" \")\n\tif len(headerParts) != 2 {\n\t\tc.AbortWithStatus(http.StatusUnauthorized)\n\t\treturn\n\t}\n\n\tif headerParts[0] != \"Bearer\" {\n\t\tc.AbortWithStatus(http.StatusUnauthorized)\n\t\treturn\n\t}\n\n\terr := parser.ParseToken(headerParts[1], SIGNING_KEY)\n\tif err != nil {\n\t\tstatus := http.StatusBadRequest\n\t\tif err == auth.ErrInvalidAccessToken {\n\t\t\tstatus = http.StatusUnauthorized\n\t\t}\n\n\t\tc.AbortWithStatus(status)\n\t\treturn\n\t}\n}\n```\n\n## API:\n\n### POST /auth/sign-up\n\nRegisters new user\n\n#### Example Input: \n```\n{\n\t\"username\": \"user\",\n\t\"password\": \"password\"\n}\n```\n\n#### Example Response: \n```\n{\n\t\"status\": \"ok\",\n\t\"message\": \"user created successfully\"\n}\n```\n\n### POST /auth/sign-in\n\nGenerates JWT Token\n\n#### Example Input: \n```\n{\n\t\"username\": \"user\",\n\t\"password\": \"password\"\n}\n```\n\n#### Example Response: \n```\n{\n\t\"status\": \"ok\",\n\t\"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7InVzZXJuYW1lIjoidXNlciIsInBhc3N3b3JkIjoiNWJhYTYxZTRjOWI5M2YzZjA2ODIyNTBiNmNmODMzMWI3ZWU2OGZkOCJ9fQ.UvCbjhn7o17cvvYRK3rr6ih0Ro_VvZZpKWns1sOH-CE\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhashkevych%2Fauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhashkevych%2Fauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhashkevych%2Fauth/lists"}