{"id":13409091,"url":"https://github.com/brianvoe/sjwt","last_synced_at":"2025-05-11T22:32:19.281Z","repository":{"id":56682188,"uuid":"192846362","full_name":"brianvoe/sjwt","owner":"brianvoe","description":"Simple JWT Golang","archived":false,"fork":false,"pushed_at":"2024-02-01T19:54:37.000Z","size":37,"stargazers_count":118,"open_issues_count":1,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-26T21:33:10.037Z","etag":null,"topics":["authentication","golang","jsonwebtoken","jwt","simple"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/brianvoe/sjwt","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/brianvoe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":"brianvoe","patreon":"brianvoe","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-06-20T04:06:21.000Z","updated_at":"2024-09-02T14:32:02.000Z","dependencies_parsed_at":"2024-06-18T15:31:23.591Z","dependency_job_id":"85d874fe-aefc-40b3-866e-9ea3e055dbc5","html_url":"https://github.com/brianvoe/sjwt","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianvoe%2Fsjwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianvoe%2Fsjwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianvoe%2Fsjwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brianvoe%2Fsjwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brianvoe","download_url":"https://codeload.github.com/brianvoe/sjwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223876417,"owners_count":17218387,"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","golang","jsonwebtoken","jwt","simple"],"created_at":"2024-07-30T20:00:57.946Z","updated_at":"2024-11-09T20:03:53.484Z","avatar_url":"https://github.com/brianvoe.png","language":"Go","readme":"![alt text](https://raw.githubusercontent.com/brianvoe/sjwt/master/logo.png)\n\n# sjwt [![Go Report Card](https://goreportcard.com/badge/github.com/brianvoe/sjwt)](https://goreportcard.com/report/github.com/brianvoe/sjwt) [![GoDoc](https://godoc.org/github.com/brianvoe/sjwt?status.svg)](https://godoc.org/github.com/brianvoe/sjwt) [![license](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/brianvoe/sjwt/master/LICENSE)\n\n\u003ca href=\"https://www.buymeacoffee.com/brianvoe\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png\" alt=\"Buy Me A Coffee\" style=\"height: auto !important;width: auto !important;\" \u003e\u003c/a\u003e\n\nSimple JSON Web Token - Uses HMAC SHA-256\n\nMinimalistic and efficient tool for handling JSON Web Tokens in Go applications. It offers a straightforward approach to integrating JWT for authentication and security, designed for ease of use.\n\n## Features\n\n- **Easy JWT for Go**: Implement JWT in Go with minimal effort.\n- **Secure \u0026 Simple**: Reliable security features, easy to integrate.\n- **Open Source**: MIT licensed, open for community contributions.\n\n## Install\n```bash \ngo get -u github.com/brianvoe/sjwt\n```\n\n## Example\n```go\n// Set Claims\nclaims := sjwt.New()\nclaims.Set(\"username\", \"billymister\")\nclaims.Set(\"account_id\", 8675309)\n\n// Generate jwt\nsecretKey := []byte(\"secret_key_here\")\njwt := claims.Generate(secretKey)\n```\n\n## Example parse\n```go\n// Parse jwt\njwt := \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\"\nclaims, _ := sjwt.Parse(jwt)\n\n// Get claims\nname, err := claims.GetStr(\"name\") // John Doe\n```\n\n## Example verify and validate\n```go\njwt := \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\"\nsecretKey := []byte(\"secret_key_here\")\n\n// Verify that the secret signature is valid\nhasVerified := sjwt.Verify(jwt, secretKey)\n\n// Parse jwt\nclaims, _ := sjwt.Parse(jwt)\n\n// Validate will check(if set) Expiration At and Not Before At dates\nerr := claims.Validate()\n```\n\n## Example usage of registered claims\n```go\n// Set Claims\nclaims := sjwt.New()\nclaims.SetTokenID()                                  // UUID generated\nclaims.SetSubject(\"Subject Title\")                   // Subject of the token\nclaims.SetIssuer(\"Google\")                           // Issuer of the token\nclaims.SetAudience([]string{\"Google\", \"Facebook\"})   // Audience the toke is for\nclaims.SetIssuedAt(time.Now())                       // IssuedAt in time, value is set in unix\nclaims.SetNotBeforeAt(time.Now().Add(time.Hour * 1)) // Token valid in 1 hour\nclaims.SetExpiresAt(time.Now().Add(time.Hour * 24))  // Token expires in 24 hours\n\n// Generate jwt\nsecretKey := []byte(\"secret_key_here\")\njwt := claims.Generate(secretKey)\n```\n\n## Example usage of struct to claims\n```go\ntype Info struct {\n    Name string `json:\"name\"`\n}\n\n// Marshal your struct into claims\ninfo := Info{Name: \"Billy Mister\"}\nclaims, _ := sjwt.ToClaims(info)\n\n// Generate jwt\nsecretKey := []byte(\"secret_key_here\")\njwt := claims.Generate(secretKey)\n```\n\n## Why?\nFor all the times I have needed the use of a jwt, its always been a simple HMAC SHA-256 and thats normally the use of most jwt tokens.\n","funding_links":["https://github.com/sponsors/brianvoe","https://patreon.com/brianvoe","https://www.buymeacoffee.com/brianvoe"],"categories":["Authentication and OAuth","身份验证和OAuth","Authentication and Authorization","认证和OAuth授权","Uncategorized"],"sub_categories":["Contents"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianvoe%2Fsjwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrianvoe%2Fsjwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrianvoe%2Fsjwt/lists"}