{"id":16965267,"url":"https://github.com/s12v/go-jwks","last_synced_at":"2025-07-19T04:32:57.689Z","repository":{"id":35001978,"uuid":"141760448","full_name":"s12v/go-jwks","owner":"s12v","description":"A Go library to retrieve RSA public keys from a JWKS (JSON Web Key Set) endpoint","archived":false,"fork":false,"pushed_at":"2023-05-08T12:56:40.000Z","size":50,"stargazers_count":42,"open_issues_count":10,"forks_count":17,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T18:09:01.947Z","etag":null,"topics":["jwk","jwks","jwt","rsa"],"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/s12v.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":"2018-07-20T21:41:27.000Z","updated_at":"2024-03-09T06:24:23.000Z","dependencies_parsed_at":"2024-06-18T16:46:48.143Z","dependency_job_id":"f93d0915-5114-4168-ae6c-e1d76b2cba95","html_url":"https://github.com/s12v/go-jwks","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/s12v/go-jwks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s12v%2Fgo-jwks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s12v%2Fgo-jwks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s12v%2Fgo-jwks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s12v%2Fgo-jwks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s12v","download_url":"https://codeload.github.com/s12v/go-jwks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s12v%2Fgo-jwks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265888897,"owners_count":23844527,"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":["jwk","jwks","jwt","rsa"],"created_at":"2024-10-13T23:45:31.993Z","updated_at":"2025-07-19T04:32:57.667Z","avatar_url":"https://github.com/s12v.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/s12v/go-jwks.svg?branch=master)](https://travis-ci.com/s12v/go-jwks)\n[![codecov](https://codecov.io/gh/s12v/go-jwks/branch/master/graph/badge.svg)](https://codecov.io/gh/s12v/go-jwks)\n# go-jwks\n\nA Go library to retrieve RSA public keys from a JWKS (JSON Web Key Set) endpoint.\n\n## Installation\n\nUsing [Go modules](https://github.com/golang/go/wiki/Modules)\n\n```bash\ngo get github.com/s12v/go-jwks@v0.2.1\n```\n\n## Dependencies\n\n * `github.com/square/go-jose` - JWT library\n * `github.com/patrickmn/go-cache` - default in-memory cache\n\n## Example\n\n`GetEncryptionKey` returns `*jose.JSONWebKey` for a given key id:\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/s12v/go-jwks\"\n\t\"github.com/square/go-jose\"\n)\n\nfunc main() {\n\tjwksSource := jwks.NewWebSource(\"https://www.googleapis.com/oauth2/v3/certs\")\n\tjwksClient := jwks.NewDefaultClient(\n\t\tjwksSource,\n\t\ttime.Hour,    // Refresh keys every 1 hour\n\t\t12*time.Hour, // Expire keys after 12 hours\n\t)\n\n\tvar jwk *jose.JSONWebKey\n\tjwk, err := jwksClient.GetEncryptionKey(\"c6af7caa0895fd01e778dceaa7a7988347d8f25c\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Printf(\"key: %v, alg: %v, use: %v\", jwk.KeyID, jwk.Algorithm, jwk.Use)\n}\n```\n\nLog:\n\n```\n2018/07/30 01:22:35 Fetchng JWKS from https://www.googleapis.com/oauth2/v3/certs\n2018/07/30 01:22:36 key: c6af7caa0895fd01e778dceaa7a7988347d8f25c, alg: RS256, use: sig\n```\n\n## Caching\n\n### Key refresh and TTL\n\nThere are two caching parameters:\n - `refresh` - the key will be fetched from the source after this interval \n - `ttl` - if not used, the key will be deleted from cache \n\nOn the first request, the key is synchronously fetched from the key server and stored in the cache.\nOn the next request after `refresh` interval, the key will be refreshed in the background (not affect response time).\nOnly 1 key refresh is executed at the same time.\n\nIf the key is not requested during `ttl` interval, it will be removed from cache.\n\n## Cache implementations\n\nDefault cache is `github.com/patrickmn/go-cache` in-memory cache.\nYou can provide your own cache implementation, see `cache.go`:\n\n```go\ntype Cache interface {\n\t// Get an item from the cache and itsexpiration time.\n\t// Returns the item or nil, and a bool indicating whether the key was found\n\tGetWithExpiration(k string) (interface{}, time.Time, bool)\n\t// Add an item to the cache, replacing any existing item.\n\tSet(k string, x interface{})\n}\n```\n\nand pass it to `func NewClient(...)`\n\n## Source\n\nDefault source is `WebSource`. You can provide your own implementation, see `source.go`:\n\n```go\ntype JWKSSource interface {\n\tJSONWebKeySet() (*jose.JSONWebKeySet, error)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs12v%2Fgo-jwks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs12v%2Fgo-jwks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs12v%2Fgo-jwks/lists"}