{"id":15983280,"url":"https://github.com/suyashkumar/auth","last_synced_at":"2025-03-17T22:31:24.409Z","repository":{"id":57605891,"uuid":"120258101","full_name":"suyashkumar/auth","owner":"suyashkumar","description":"A simple Golang authentication library with batteries included (hashing, permissions, validation, etc)","archived":false,"fork":false,"pushed_at":"2018-08-22T04:33:04.000Z","size":30,"stargazers_count":5,"open_issues_count":6,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-28T05:47:59.278Z","etag":null,"topics":["auth","authentication","automatic-authentication","golang","library","login"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/suyashkumar.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}},"created_at":"2018-02-05T05:15:24.000Z","updated_at":"2025-01-10T19:47:18.000Z","dependencies_parsed_at":"2022-09-26T20:01:57.527Z","dependency_job_id":null,"html_url":"https://github.com/suyashkumar/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/suyashkumar%2Fauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyashkumar%2Fauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyashkumar%2Fauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyashkumar%2Fauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suyashkumar","download_url":"https://codeload.github.com/suyashkumar/auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243891597,"owners_count":20364595,"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":["auth","authentication","automatic-authentication","golang","library","login"],"created_at":"2024-10-08T01:41:34.677Z","updated_at":"2025-03-17T22:31:24.174Z","avatar_url":"https://github.com/suyashkumar.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# auth\n[![Godoc Reference](https://godoc.org/github.com/suyashkumar/auth?status.svg)](https://godoc.org/github.com/suyashkumar/auth)\n[![Go Report Card](https://goreportcard.com/badge/github.com/suyashkumar/auth)](https://goreportcard.com/report/github.com/suyashkumar/auth)\n\nA simple (but opinionated) Golang authentication library with a very simple interface (below). You can use this library to pull in core authentication functionality (minting tokens, validating tokens, \u0026 registering) to your application quickly and easily. \n\n```go\ntype Auth interface {\n\tRegister(user User, password string) error\n\tGetToken(email string, password string, reqPermissions Permissions) (token string, err error)\n\tValidate(token string) (*Claims, error)\n}\n```\n\nA gRPC microservice wrapping this interface is in progress and can be found at [suyashkumar/auth-grpc](https://github.com/suyashkumar/auth-grpc).\n\nYou only need to provide a database `connectionString` and `signingKey`, and everything else is taken care of for you including:\n* table and database setup (including uniqueness constraints and useful indicies)\n* hashing passwords using `bcrypt` on register\n* comparing hashed passwords on login\n* validation of new user fields like \"Email\" (TBD)\n* encoding and extraction of key fields stored in the JSON Web Token (JWT)\n* ensuring that a token's requested permissions does not exceed the user's maximum permission level\n\nA minimal example is below:\n```go\na, _ := auth.NewAuthenticator(db_string, signing_key)\n\nu := auth.User{\n\tUUID:               uuid.NewV4(),\n\tEmail:              \"test@test.com\",\n\tMaxPermissionLevel: auth.PERMISSIONS_USER,\n}\n\n// Register a new user\na.Register(u, \"password\")\n\n// Login as user\ntoken, err := a.GetToken(u.Email, \"password\", auth.PERMISSIONS_USER)\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"JWT Token: %s\\n\\n\", token)\n\n// Validate the user's token\nclaims, _ := a.Validate(token)\nfmt.Printf(\"%+v\", claims)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuyashkumar%2Fauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuyashkumar%2Fauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuyashkumar%2Fauth/lists"}