{"id":34213614,"url":"https://github.com/n10ty/authless","last_synced_at":"2026-04-21T01:32:25.454Z","repository":{"id":47194302,"uuid":"482276641","full_name":"n10ty/authless","owner":"n10ty","description":"Registration/authentication ready-to-use library for Go","archived":false,"fork":false,"pushed_at":"2022-06-05T20:09:37.000Z","size":344,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-04-14T08:39:56.628Z","etag":null,"topics":["authentication","gin-gonic","go","gorilla-mux","registration"],"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/n10ty.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}},"created_at":"2022-04-16T14:32:39.000Z","updated_at":"2022-08-08T19:59:53.000Z","dependencies_parsed_at":"2022-08-29T14:21:23.636Z","dependency_job_id":null,"html_url":"https://github.com/n10ty/authless","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/n10ty/authless","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n10ty%2Fauthless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n10ty%2Fauthless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n10ty%2Fauthless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n10ty%2Fauthless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/n10ty","download_url":"https://codeload.github.com/n10ty/authless/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n10ty%2Fauthless/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32072953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T21:26:33.338Z","status":"ssl_error","status_checked_at":"2026-04-20T21:26:22.081Z","response_time":94,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["authentication","gin-gonic","go","gorilla-mux","registration"],"created_at":"2025-12-15T21:54:44.938Z","updated_at":"2026-04-21T01:32:25.447Z","avatar_url":"https://github.com/n10ty.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Authless - easy setup user authentication lib \n\nThis library provide user login/registration feature based\non cookie JWT token with multiple storage support. \n\n* Registration\n* Login\n* JWT token via cookie\n* XSRF protection\n* Out of the box HTML templates read to use\n* Or use it only as a backend with your own frontend\n* Confirmation token\n* Multiple router supports (Gin, standard, etc.)\n* Multiple storage supports (Mysql, Postgres, config, \"create your own\", ...)\n\n## Fast start\nWith Gin ([Routers](#Routers)):\n``` go\nfunc main() {\n\tconfigPath := \"./default.yml\"\n\tauth, err := authless.NewGinAuth(configPath)\n\tif err != nil {\n\t\tlog.Println(err)\n\t\treturn\n\t}\n\tauth.SetTokenSender(func(email, token string) error {\n\t\tfmt.Println(\"TOKEN SEND\", token)\n\t\treturn nil\n\t})\n\n\trouter := gin.Default()\n\tauth.InitServiceRoutes(router)\n\n\trouter.GET(\"/ping\", func(c *gin.Context) {\n\t\tc.String(200, \"pong\")\n\t})\n\n\trouter.Handle(\"GET\", \"/private\", auth.AuthRequired(func(c *gin.Context) {\n\t\tc.String(200, \"private\")\n\t}))\n\n\trouter.GET(\"/public\", func(c *gin.Context) {\n\t\tc.String(200, \"public\")\n\t})\n\tlog.Fatal(http.ListenAndServe(\":8080\", router))\n}\n```\n\n## Config\nYou can create config object in code:\n```go\nconfig := \u0026authless.Config{\n    Host:               \"example.com\", // this will used for activation/forget-password links\n    Secret:             \"d123\",\n    DisableXSRF:        true,\n    TokenDuration:      time.Minute,\n    CookieDuration:     time.Minute,\n    Storage:            storage.Config{\n        Type:            \"mysql\",   // mysql, const (setup by config), postgres, inmemory\n        Host:            \"localhost\",\n        Port:            3306,\n        Username:        \"user\",\n        Password:        \"pass\",\n        Dbname:          \"myusers\",\n    },\n    Type:               authless.AuthTypeTemplate, // 'template' or 'api'\n    LogLevel:           \"debug\", // debug, info, warning, error\n    TemplatePath:       \"\", // path to template folder\n    Validator:          nil,\n}\n```\n\nor parse it from yaml:\n```go\npath := \"./default.yml\"\nconf, err := authless.ReadConfig(path)\n```\n\n**Caveat: yaml parser property names are case-insensitive**\n\n## HTML templates\n\nThere are ready to use html login/registration forms. To use it\ncopy `template` folder to your project root.\n\n![Image](/login-form.png)\n\n## Routers\n\n### Gin\nWe recommend to use [Gin](https://github.com/gin-gonic/gin) as main router.\nTo create new `auth`:\n```go\nauth, err := authless.NewGorillaAuth(conf)\n```\n\nTo add service routes:\n```go\nrouter := gin.Default()\nauth.InitServiceRoutes(router)\n```\n\nIf you need to restrict unauthorized access to route wrap handler with `AuthRequired`:\n```go\nrouter.Handle(\"GET\", \"/private\", auth.AuthRequired(func(c *gin.Context) {\n    c.String(200, \"private\")\n}))\n```\n\nDon't forget to setup _password change_ and _password forget_:\n```go\nauth.SetActivationTokenSenderFunc(func(email, token string) error {\n    fmt.Println(\"TOKEN SEND\", token)\n    return nil\n})\nauth.SetChangePasswordRequestFunc(func(email, token string) error {\n    fmt.Println(\"TOKEN SEND\", token)\n    return nil\n})\n```\n\n### Gorilla mux\nAdapter for [Gorilla router](https://github.com/gorilla/mux)\nUse it in the same way as Gin, except creating:\n```go\nauth, err := authless.NewGorillaAuth(conf)\n```\n\n## API Routes\n\n### Login\nCall GET ```/auth/login?email=test@example.com\u0026passwd=xyz```\nor send POST form\n```json\n{\n    \"email\": \"test@example.com\",\n    \"password\": \"xyz\"\n}\n```\n\n### Logout\nCall GET `/auth/logout` to remove cookie and blacklist token (see todo)\n\n### Register\nSend POST form ```/auth/register```\n```json\n{\n    \"email\": \"test@example.com\",\n    \"password\": \"xyz\"\n}\n```\nto create new user. Created user is not active and unable to login.\n\n#### Send activation token\n\nUse `ActivateAccountFunc = func(email, url, token string) error` to send token during registration\n\nExample:\n```go\nauth, _ := authless.NewGinAuth(configPath)\nclient := NewMailerClient(somekey)\nauth.SetActivationTokenSenderFunc(func(email, activateUrl, token string) error {\n    //make user go to activateUrl to activate accoung\n    return client.SendEmail(email, token)\n})\n```\n\n### Activate\nCall GET ```/auth/activate?token=mytoken```\nto activate account to able account to login\n\n### Forget password\nTo send change password send POST form to ```/auth/forget-password```:\n\n    {\n        \"email\": \"test@example.com\",\n    }\nThis will generate new token and execute `ChangePasswordRequestFunc`\n\n#### Send change password token\nUse:\n\n`type ChangePasswordRequestFunc = func(email, token string) error`\n\nExample:\n```go\nauth, _ := authless.NewGinAuth(configPath)\nclient := NewMailerClient(somekey)\nauth.SetChangePasswordRequestFunc(func(email, url, token string) error {\n    return client.SendChangePassword\n})\n```\n\n### Change password\nTo change password send POST form to `/auth/change-password`\n\n    {\n        \"email\": \"test@example.com\",\n        \"token\": \"TOKEN\", //TOKEN sent by ChangePasswordRequestFunc\n        \"password\": \"newpassword\",\n    }\n\n## HTML Routes\nTo override page:\n* create your own html page\n* insert _Vars_ into your template. Under _Var_ message or error text will be displayed\n* rename html and put under _Template path_\n* template will be available under _Path_\n\nList of available routes:\n\n#### Login\nPath: `/login` \\\nTemplate path: `template/login_form.html` \\\nVars: `{{.error}}`\n\n#### Logout\nPath: `/logout` \\\nTemplate path: -\n\n#### Registration form\nPath: `/register` \\\nTemplate path: `template/registration_form.html` \\\nVars: `{{.error}}`\n\n#### Registration success page\nPath: `/register/result` \\\nTemplate path: `template/registration_form.html` \\\nVars: `{{.message}}`\n\n#### Activate result\nPath: `/activate/result` \\\nTemplate: `template/activation_result.html` \\\nVars: `{{.error}}` `{{.message}}`\n\n#### Forget password form\nDescription: display form for password remind\nPath: `/forget-password` \\\nTemplate: `template/forget_password_form.html` \\\nVars: `{{.error}}`\n\n#### Forget password result page\nDescription: page to show after successfully remind password submission  \nPath: `/forget-password/result` \\\nTemplate: `template/forget_password_result.html` \\\nVars: `{{.error}}` `{{.message}}`\n\n#### Change password form\nDescription: display change password form  \nPath: `/change-password` \\\nTemplate: `template/change_password_form.html` \\\nVars: `{{.error}}`\n\n#### Change password result page\nDescription: page to show after successfully change password submission\nPath: `/change-password/result` \\\nTemplate: `template/change_password_result.html` \\\nVars: `{{.error}}` `{{.message}}`\n\n\n-----------------------------------\n\n\n## Todo:\n\n- [x] Add tests\n- [x] Add gorilla http router\n- [x] Add default http router\n- [x] Forget password mux\n- [x] Forget password gorilla\n- [x] Get rid of /r/\n- [x] Add global auth.GetUser method\n- [x] Fully get rid of authz package\n- [ ] Load default html template\n- [ ] Validate html present\n- [x] Finish README\n- [ ] Add postgres\n- [ ] Validate config\n- [ ] Pass full url to forget pass/validate acc functions\n- [ ] Blacklist of expired tokens (after logout token invalid)\n- [ ] Get rid of error message in query ?error=bad request\n- [x] Routes as const\n- [ ] Min config to start: storage only\n- [ ] Check successurl\n- [ ] Add \"Activate password\" callback\n- [ ] Audit log","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn10ty%2Fauthless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fn10ty%2Fauthless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn10ty%2Fauthless/lists"}