{"id":28479378,"url":"https://github.com/rayato159/rainbowhatto","last_synced_at":"2025-07-03T15:31:55.806Z","repository":{"id":65963436,"uuid":"603037085","full_name":"Rayato159/rainbowhatto","owner":"Rayato159","description":"The package to implement authentication (jwt-based) and authorization (in progress...) in Golang.","archived":false,"fork":false,"pushed_at":"2023-02-20T04:33:58.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-07T18:09:01.586Z","etag":null,"topics":["authentication","backend-service","golang","jwt-authentication"],"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/Rayato159.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,"publiccode":null,"codemeta":null}},"created_at":"2023-02-17T13:43:35.000Z","updated_at":"2023-05-03T17:43:06.000Z","dependencies_parsed_at":"2023-02-20T20:31:20.565Z","dependency_job_id":null,"html_url":"https://github.com/Rayato159/rainbowhatto","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":"0.30000000000000004","last_synced_commit":"fa3eff432a680c85f0e8b31024f9f0e13f38b5e3"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Rayato159/rainbowhatto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rayato159%2Frainbowhatto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rayato159%2Frainbowhatto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rayato159%2Frainbowhatto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rayato159%2Frainbowhatto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rayato159","download_url":"https://codeload.github.com/Rayato159/rainbowhatto/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rayato159%2Frainbowhatto/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263350373,"owners_count":23453274,"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":["authentication","backend-service","golang","jwt-authentication"],"created_at":"2025-06-07T18:09:04.611Z","updated_at":"2025-07-03T15:31:55.763Z","avatar_url":"https://github.com/Rayato159.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003e🌈 Rainbow Hatto\u003c/h1\u003e\n\n\u003cstrong\u003eRainbow Hatto is the \u003cstrong\u003eauthentication\u003c/strong\u003e and \u003cstrong\u003eauthorization\u003c/strong\u003e package for Golang.\u003c/strong\u003e\n\n\u003cp\u003eThe authentication is based on \u003cstrong\u003eJwt (Json Web Token) \u003c/strong\u003e and the authorization methodology is \u003cstrong\u003ebased on role-based access control (RBAC)\u003c/strong\u003e\u003c/p\u003e\n\n\u003ch2\u003eContent\u003c/h2\u003e\n\u003cul\u003e\n    \u003cli\u003e\u003ca href=\"#intstallation\"\u003eInstallation\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#function\"\u003eFunction\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"#type\"\u003eType\u003c/a\u003e\u003c/li\u003e\n    \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#signalgorithm\"\u003eSignAlgorithm\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#claims\"\u003eClaims\u003c/a\u003e\u003c/li\u003e\n    \u003c/ul\u003e\n    \u003cli\u003e\u003ca href=\"#quickstart\"\u003eQuickstart\u003c/a\u003e\u003c/li\u003e\n    \u003cul\u003e\n        \u003cli\u003e\u003ca href=\"#hmac\"\u003eHMAC Token\u003c/a\u003e\u003c/li\u003e\n        \u003cli\u003e\u003ca href=\"#rsa\"\u003eRSA token\u003c/a\u003e\u003c/li\u003e\n    \u003c/ul\u003e\n\u003c/ul\u003e\n\n\u003ch2 id=\"intstallation\"\u003eInstallation\u003c/h2\u003e\n\n```bash\ngo get github.com/Rayato159/rainbowhatto\n```\n\n\u003ch2 id=\"function\"\u003eFunction\u003c/h2\u003e\n\n```go\nfunc BuildToken(alg src.SignAlgorithm, cfg Config) src.IToken {...}\nfunc ReverseHMACToken(token string, secret string) (*Claims, error) {...}\nfunc ReverseRSAToken(token string, path string) (*Claims, error) {...}\nfunc RefreshToken(alg src.SignAlgorithm, token string, cfg Config) (src.IToken, error) {...}\n```\n\n\u003ch2 id=\"type\"\u003eType\u003c/h2\u003e\n\n\u003ch3 id=\"signalgorithm\"\u003eSignAlgorithm\u003c/h3\u003e\n\u003cp\u003eJust call a below function to get a SignAlgorithm type\u003c/p\u003e\n\n```go\nfunc HMAC() src.SignAlgorithm {...} // return HMAC type\nfunc RSA() src.SignAlgorithm {...} // return RSA type\n```\n\n\u003ch3 id=\"claims\"\u003eClaims\u003c/h3\u003e\n\n```go\ntype Claims struct {\n\t*src.NewClaims `json:\"claims\"`\n}\n\ntype NewClaims struct {\n\tClaims any `json:\"claims\"`\n\tjwt.RegisteredClaims\n}\n```\n\nDetail of registered claims\n```txt\nID:        xid,\nIssuer:    \"rainbowhatto\",\nSubject:   \"rainbowtoken\",\nAudience:  [\"human\"],\nExpiresAt: time exp,\nNotBefore: time now,\nIssuedAt:  time now,\n```\n\n\u003ch2 id=\"quickstart\"\u003eQuickstart\u003c/h2\u003e\n\n\u003ch3 id=\"hmac\"\u003eHMAC token (Symmetric key)\u003c/h3\u003e\n\n\u003cp\u003eSign Token\u003c/p\u003e\n\n```go\nfunc main() {\n\ttoken, err := rainbowhatto.BuildToken(rainbowhatto.HMAC(), rainbowhatto.Config{\n\t\tExpiresAt: 86400,\n\t\tHMAC: \u0026rainbowhatto.HMACConfig{\n\t\t\tSecret: \"super-secret\",\n\t\t},\n\t\tClaims: claims{\n\t\t\tId:   \"abdcefg1234\",\n\t\t\tName: \"rainbow\",\n\t\t},\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(token.SignToken())\n}\n```\n\n\u003cp\u003eParse Token\u003c/p\u003e\n\n```go\nfunc main() {\n    token := \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGFpbXMiOnsiSWQiOiJhYmRjZWZnMTIzNCIsIk5hbWUiOiJyYWluYm93In0sImlzcyI6InJhaW5ib3doYXR0byIsInN1YiI6InJhaW5ib3d0b2tlbiIsImF1ZCI6WyJodW1hbiJdLCJleHAiOjE2NzY4MjcxMzIsIm5iZiI6MTY3Njc0MDczMiwiaWF0IjoxNjc2NzQwNzMyLCJqdGkiOiJjZm9nZ3Y2bmRyYzBibjRyOGQ4MCJ9.lzBu_zRgtc0oTqkZyjatJu7u8PGeBXALcICdTf7zUcs\"\n    claims, err := rainbowhatto.ReverseHMACToken(token, \"super-secret\")\n    if err != nil {\n        panic(err)\n    }\n    fmt.Println(claims)\n}\n```\n\n\u003cp\u003eRefresh Token\u003c/p\u003e\n\n```go\nfunc main() {\n    oldToken := \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGFpbXMiOnsiSWQiOiJhYmRjZWZnMTIzNCIsIk5hbWUiOiJyYWluYm93In0sImlzcyI6InJhaW5ib3doYXR0byIsInN1YiI6InJhaW5ib3d0b2tlbiIsImF1ZCI6WyJodW1hbiJdLCJleHAiOjE2NzY4MjcxMzIsIm5iZiI6MTY3Njc0MDczMiwiaWF0IjoxNjc2NzQwNzMyLCJqdGkiOiJjZm9nZ3Y2bmRyYzBibjRyOGQ4MCJ9.lzBu_zRgtc0oTqkZyjatJu7u8PGeBXALcICdTf7zUcs\"\n\n    newToken, err := rainbowhatto.RefreshToken(rainbowhatto.HMAC(), oldToken, rainbowhatto.Config{\n\t\tExpiresAt: 0,\n\t\tHMAC: \u0026rainbowhatto.HMACConfig{\n\t\t\tSecret: \"super-secret\",\n\t\t},\n\t\tClaims: claims{\n\t\t\tId:   \"abdcefg1234\",\n\t\t\tName: \"rainbow\",\n\t\t},\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(newToken.SignToken())\n}\n```\n\n\u003ch3 id=\"rsa\"\u003eRSA token (asymmetric key)\u003c/h3\u003e\n\n\u003cp\u003eFirst Generate a .pem key by the following command as below\u003c/p\u003e\n\n```bash\n# Gen a private key (the number is just a bytes)\nopenssl genrsa -out \u003cfile_name\u003e.pem 2048\n\n# Get a public key\nopenssl rsa -in \u003cfile_name\u003e.pem -pubout -out public.pem\n```\n\n\u003cp\u003eSign Token\u003c/p\u003e\n\n```go\nfunc main() {\n\ttoken, err := rainbowhatto.BuildToken(rainbowhatto.RSA(), rainbowhatto.Config{\n\t\tExpiresAt: 86400,\n\t\tRSA: \u0026rainbowhatto.RSAConfig{\n\t\t\tPrivateKey: \"./private_key.pem\",\n\t\t},\n\t\tClaims: claims{\n\t\t\tId:   \"abdcefg1234\",\n\t\t\tName: \"rainbow\",\n\t\t},\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(token.SignToken())\n}\n```\n\n\u003cp\u003eParse Token\u003c/p\u003e\n\n```go\nfunc main() {\n    token := \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGFpbXMiOnsiSWQiOiJhYmRjZWZnMTIzNCIsIk5hbWUiOiJyYWluYm93In0sImlzcyI6InJhaW5ib3doYXR0byIsInN1YiI6InJhaW5ib3d0b2tlbiIsImF1ZCI6WyJodW1hbiJdLCJleHAiOjE2NzY4MjcxNTIsIm5iZiI6MTY3Njc0MDc1MiwiaWF0IjoxNjc2NzQwNzUyLCJqdGkiOiJjZm9naDQ2bmRyYzRwODc0MHBjZyJ9.NSB3DoBjw4XNkiB8_Cnw29qioVp1Y9nRBj5To-k-_yldx74hquGEvni7ZyHio_eAoPRAbi8EdZNNtLyt0wSl3bLvzgsl4b5fvHnVfcp55i9lyUH0odDHnNXq7fWOcNqH4QaMVF2LcJ66AffjDgiePbR7ob8YyovgMDYjU4x73wkyrzNqAJBugbjgBX9g1wd-aGo9N1i0sYas6YBMRbQAhl4XrtVpZj-YQkHePYYrU6Xt6DiE5vhtAuiDRqD4B9gXOStHV6VtLVnjAFJSFidYAXjV0GKzdaOl84yddNL2ZSwFf6JcD4AJ7AGuIlXmA7EC5yC5pwKjVNcFopVZjUKjyA\"\n    claims, err := rainbowhatto.ReverseHMACToken(token, \"./public.pem\") // Public key path\n    if err != nil {\n        panic(err)\n    }\n    fmt.Println(claims)\n}\n```\n\n\u003cp\u003eRefresh Token\u003c/p\u003e\n\n```go\nfunc main() {\n    oldToken := \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGFpbXMiOnsiSWQiOiJhYmRjZWZnMTIzNCIsIk5hbWUiOiJyYWluYm93In0sImlzcyI6InJhaW5ib3doYXR0byIsInN1YiI6InJhaW5ib3d0b2tlbiIsImF1ZCI6WyJodW1hbiJdLCJleHAiOjE2NzY4MjcxNTIsIm5iZiI6MTY3Njc0MDc1MiwiaWF0IjoxNjc2NzQwNzUyLCJqdGkiOiJjZm9naDQ2bmRyYzRwODc0MHBjZyJ9.NSB3DoBjw4XNkiB8_Cnw29qioVp1Y9nRBj5To-k-_yldx74hquGEvni7ZyHio_eAoPRAbi8EdZNNtLyt0wSl3bLvzgsl4b5fvHnVfcp55i9lyUH0odDHnNXq7fWOcNqH4QaMVF2LcJ66AffjDgiePbR7ob8YyovgMDYjU4x73wkyrzNqAJBugbjgBX9g1wd-aGo9N1i0sYas6YBMRbQAhl4XrtVpZj-YQkHePYYrU6Xt6DiE5vhtAuiDRqD4B9gXOStHV6VtLVnjAFJSFidYAXjV0GKzdaOl84yddNL2ZSwFf6JcD4AJ7AGuIlXmA7EC5yC5pwKjVNcFopVZjUKjyA\"\n\n    newToken, err := rainbowhatto.RefreshToken(rainbowhatto.RSA(), oldToken, rainbowhatto.Config{\n\t\tRSA: \u0026rainbowhatto.RSAConfig{\n\t\t\tPrivateKey: \"./private_key.pem\",\n\t\t\tPublicKey:  \"./public_key.pem\",\n\t\t},\n\t\tClaims: claims{\n\t\t\tId:   \"abdcefg1234\",\n\t\t\tName: \"rainbow\",\n\t\t},\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(newToken.SignToken())\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayato159%2Frainbowhatto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frayato159%2Frainbowhatto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayato159%2Frainbowhatto/lists"}