{"id":18832588,"url":"https://github.com/linka-cloud/oidc-handlers","last_synced_at":"2025-06-25T12:36:41.647Z","repository":{"id":43881534,"uuid":"404303981","full_name":"linka-cloud/oidc-handlers","owner":"linka-cloud","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-17T14:12:47.000Z","size":157,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-29T17:31:03.216Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linka-cloud.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":"2021-09-08T10:24:34.000Z","updated_at":"2021-12-13T11:14:19.000Z","dependencies_parsed_at":"2024-06-21T08:42:34.701Z","dependency_job_id":null,"html_url":"https://github.com/linka-cloud/oidc-handlers","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/linka-cloud/oidc-handlers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Foidc-handlers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Foidc-handlers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Foidc-handlers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Foidc-handlers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linka-cloud","download_url":"https://codeload.github.com/linka-cloud/oidc-handlers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linka-cloud%2Foidc-handlers/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261875395,"owners_count":23223324,"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":[],"created_at":"2024-11-08T01:58:18.869Z","updated_at":"2025-06-25T12:36:41.607Z","avatar_url":"https://github.com/linka-cloud.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OIDC Http Handlers\n\nA set of handlers to easily implements OIDC auth in applications.\n\n### Getting Started\n\nA [docker-compose.yml](docker-compose.yml) is available for testing:\n\n```bash\ndocker-compose up -d\n```\n\n[Example App](example-test/example.go):\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"encoding/json\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/sirupsen/logrus\"\n\n\toidch \"go.linka.cloud/oidc-handlers\"\n)\n\nfunc main() {\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\tconfig := oidch.Config{\n\t\tIssuerURL:     \"http://localhost:5556\",\n\t\tClientID:      \"oidc\",\n\t\tClientSecret:  \"0TJ3992YlriTfyuTgcO81L8b6eZWlWwKC2Gqij5nR44\",\n\t\tOauthCallback: \"http://example.localhost:8888/auth/callback\",\n\t}\n\tdevCtx, cancel := context.WithTimeout(ctx, 30 * time.Second)\n\tdefer cancel()\n\n\t// Perform single device auth flow\n\tif err := device(devCtx, config); err != nil {\n\t\tlogrus.Fatal(err)\n\t}\n\t// Start web app\n\tif err := web(ctx, config); err != nil {\n\t\tlogrus.Fatal(err)\n\t}\n}\n\nfunc device(ctx context.Context, config oidch.Config) error {\n\tdh, err := config.DeviceHandler(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tv, err := dh.Exchange(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\tlogrus.Infof(\"Please visit %s to authenticate\", v.URI())\n\tif _, _, err := v.Verify(ctx); err != nil {\n\t\treturn err\n\t}\n\tlogrus.Infof(\"Device authentication succeed\")\n\treturn nil\n}\n\nfunc web(ctx context.Context, config oidch.Config) error {\n\toidc, err := config.WebHandler(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\thttp.HandleFunc(\"/auth\", oidc.RedirectHandler)\n\thttp.HandleFunc(\"/auth/callback\", oidc.CallbackHandler)\n\thttp.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tif _, err := oidc.Refresh(w, r); err != nil {\n\t\t\tlogrus.Error(err)\n\t\t\toidc.SetRedirectCookie(w, \"/\")\n\t\t\thttp.Redirect(w, r, \"/auth\", http.StatusSeeOther)\n\t\t\treturn\n\t\t}\n\t\tc, ok := oidch.ClaimsFromContext(r.Context())\n\t\tif !ok {\n\t\t\thttp.Error(w, \"no claims found\", http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t\tjson.NewEncoder(w).Encode(c)\n\t})\n\tlm := func (next http.Handler) http.Handler {\n\t\treturn http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\t\tlogrus.WithFields(logrus.Fields{\"path\": r.URL.Path, \"method\": r.Method, \"remote\": r.RemoteAddr}).Info(\"new request\")\n\t\t\tnext.ServeHTTP(w, r)\n\t\t})\n\t}\n\tlogrus.Info(\"Starting web server at http://example.localhost:8888\")\n\treturn http.ListenAndServe(\":8888\", lm(http.DefaultServeMux))\n}\n\n```\n\nApplication is available at http://example.localhost:8888\n**Email**: admin@example.com\n**Password**: password\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinka-cloud%2Foidc-handlers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinka-cloud%2Foidc-handlers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinka-cloud%2Foidc-handlers/lists"}