{"id":19453802,"url":"https://github.com/osstotalsoft/oidc-jwt-go","last_synced_at":"2025-04-25T04:30:59.994Z","repository":{"id":46562762,"uuid":"174541696","full_name":"osstotalsoft/oidc-jwt-go","owner":"osstotalsoft","description":"OpenID Connect package to secure your API using JWT Bearer tokens","archived":false,"fork":false,"pushed_at":"2022-02-14T04:15:39.000Z","size":17,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-03T16:39:09.862Z","etag":null,"topics":["go","oidc","openid","openid-connect"],"latest_commit_sha":null,"homepage":null,"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/osstotalsoft.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":"2019-03-08T13:23:08.000Z","updated_at":"2025-02-04T04:08:17.000Z","dependencies_parsed_at":"2022-09-12T02:21:30.066Z","dependency_job_id":null,"html_url":"https://github.com/osstotalsoft/oidc-jwt-go","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/osstotalsoft%2Foidc-jwt-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osstotalsoft%2Foidc-jwt-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osstotalsoft%2Foidc-jwt-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osstotalsoft%2Foidc-jwt-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osstotalsoft","download_url":"https://codeload.github.com/osstotalsoft/oidc-jwt-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250754628,"owners_count":21481847,"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":["go","oidc","openid","openid-connect"],"created_at":"2024-11-10T17:06:22.290Z","updated_at":"2025-04-25T04:30:57.739Z","avatar_url":"https://github.com/osstotalsoft.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oidc-jwt-go\nOpenID Connect package to secure your API using JWT Bearer tokens.\nIt uses [dgrijalva/jwt-go](https://github.com/golang-jwt/jwt) for jwt decoding and signature verification\n \n## Installation\n`go get \"github.com/osstotalsoft/oidc-jwt-go\" `\n\n## Usage\n````go\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\tjwtRequest \"github.com/golang-jwt/jwt/request\"\n\t\"github.com/osstotalsoft/oidc-jwt-go\"\n)\n\nfunc middleware() func(next http.Handler) http.Handler {\n\tauthority := \"https://accounts.google.com\" //or other OIDC provider\n\taudience := \"YOUR_API_NAME\"\n\n\tsecretProvider := oidc.NewOidcSecretProvider(discovery.NewClient(discovery.Options{authority}))\n\tvalidator := oidc.NewJWTValidator(jwtRequest.OAuth2Extractor, secretProvider, audience, authority)\n\n\treturn func(next http.Handler) http.Handler {\n\t\treturn http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {\n\t\t\ttoken, err := validator(request)\n\t\t\tif err != nil {\n\t\t\t\tlog.Error(\"AuthorizationFilter: Token is not valid\", err)\n\t\t\t\tUnauthorizedWithHeader(writer, err.Error())\n\t\t\t\treturn\n\t\t\t}\n\t\t\tnext.ServeHttp(writer, request)\n\t\t})\n\t}\n}\n\n//UnauthorizedWithHeader adds to the response a WWW-Authenticate header and returns a StatusUnauthorized error\nfunc UnauthorizedWithHeader(writer http.ResponseWriter, err string) {\n\twriter.Header().Set(\"WWW-Authenticate\", \"Bearer error=\\\"invalid_token\\\", error_description=\\\"\"+err+\"\\\"\")\n\thttp.Error(writer, \"\", http.StatusUnauthorized)\n}\n````\n\n## Caching \nThe Secret Provider uses a simple sync.Map, with no expiration, to cache the rsa.PublicKey by a Key ID string  \n\n## TODO\n - Token Introspection [rfc7662](https://tools.ietf.org/html/rfc7662)\n - UserInfo [UserInfo](https://openid.net/specs/openid-connect-core-1_0.html#UserInfo)\n \n## Similar projects\n - https://github.com/auth0-community/go-auth0\n - https://github.com/auth0/go-jwt-middleware\n - https://github.com/appleboy/gin-jwt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosstotalsoft%2Foidc-jwt-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosstotalsoft%2Foidc-jwt-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosstotalsoft%2Foidc-jwt-go/lists"}