{"id":15965194,"url":"https://github.com/bwplotka/go-tokenauth","last_synced_at":"2025-04-04T13:26:13.123Z","repository":{"id":57614071,"uuid":"100502175","full_name":"bwplotka/go-tokenauth","owner":"bwplotka","description":"Bunch of useful token based auth sources!","archived":false,"fork":false,"pushed_at":"2017-08-17T12:01:38.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-30T04:28:34.431Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/bwplotka.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":"2017-08-16T15:07:07.000Z","updated_at":"2020-02-17T20:32:47.000Z","dependencies_parsed_at":"2022-09-11T01:00:46.086Z","dependency_job_id":null,"html_url":"https://github.com/bwplotka/go-tokenauth","commit_stats":null,"previous_names":["bplotka/go-tokenauth"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwplotka%2Fgo-tokenauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwplotka%2Fgo-tokenauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwplotka%2Fgo-tokenauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bwplotka%2Fgo-tokenauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bwplotka","download_url":"https://codeload.github.com/bwplotka/go-tokenauth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247183891,"owners_count":20897668,"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-10-07T17:40:22.273Z","updated_at":"2025-04-04T13:26:13.107Z","avatar_url":"https://github.com/bwplotka.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-tokenauth\n[![Build Status](https://travis-ci.org/Bplotka/go-tokenauth.svg?branch=master)](https://travis-ci.org/Bplotka/go-tokenauth) [![Go Report Card](https://goreportcard.com/badge/github.com/Bplotka/go-tokenauth)](https://goreportcard.com/report/github.com/Bplotka/go-tokenauth)\n\n\nThis package contains different useful Auth Sources that can return valid auth token for future use in a form of string.\n\nIt also contains tiny interface called `tokenauth.Source` that allows to create more generic (e.g HTTP, gRPC) Clients:\n\n```go\ntype Source interface {\n\t// Name of the auth source.\n\tName() string\n\n\t// Token allows the source to return a valid token for specific authorization type in a form of string.\n\t//\n\t// Example usage:\n\t// - filling Authorization HTTP header with valid auth.\n\t// In that case it is up to caller to properly save it into specific http request header (usually called \"Authorization\")\n\t// and add \"bearer\" prefix if needed.\n\tToken(context.Context) (string, error)\n}\n```\n\n## Example usage:\n\nThe usefulness of this interface can be shown in this example, when we wrap http.RoundTripper to inject required auth:\n\n```go\npackage example\n\nimport (\n    \"fmt\"\n    \"net/http\"\n    \n    \"github.com/Bplotka/go-tokenauth\"\n    \"github.com/Bplotka/go-tokenauth/direct\"\n)\n\nfunc newExampleTripper(parent http.RoundTripper /* , \u003cany configuration here\u003e */) http.RoundTripper {\n    auth := directauth.New(\"direct\", \"token1\")\n      // or:\n      // oidcauth.New(...)\n      // oauth2auth.New(...)\n      // k8sauth.New(...)\n\n    return \u0026exampleTripper{\n        parent: parent,\n        auth: auth,\n    }\n}\n\ntype exampleTripper struct {\n    parent http.RoundTripper\n    auth tokenauth.Source\n}\n\nfunc (t *exampleTripper) RoundTrip(req *http.Request) (*http.Response, error) {\n    token, err := t.auth.Token(req.Context())\n    if err != nil {\n        // handle err\n    }\n    \n    req.Header.Set(\"Authorization\", fmt.Sprintf(\"Bearer %s\", token))\n    return t.parent.RoundTrip(req)\n}\n\n```\n\nSee ready to use [tripper](./http/tripper.go)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwplotka%2Fgo-tokenauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbwplotka%2Fgo-tokenauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbwplotka%2Fgo-tokenauth/lists"}