{"id":18851745,"url":"https://github.com/greenvine/gcp-auth-util","last_synced_at":"2026-02-03T23:30:18.304Z","repository":{"id":89389405,"uuid":"282273868","full_name":"GreenVine/gcp-auth-util","owner":"GreenVine","description":"Standalone Service Account Token Generator for Google Cloud Platform (Supports Cloud Run)","archived":false,"fork":false,"pushed_at":"2020-07-28T14:17:44.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-30T16:53:27.321Z","etag":null,"topics":["authentication","cloud-run","google-cloud-platform","service-account","token"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GreenVine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","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":"2020-07-24T16:59:50.000Z","updated_at":"2020-09-16T03:03:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"59add87e-a33f-4fd8-9b2b-0e5e5412f61d","html_url":"https://github.com/GreenVine/gcp-auth-util","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GreenVine%2Fgcp-auth-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GreenVine%2Fgcp-auth-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GreenVine%2Fgcp-auth-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GreenVine%2Fgcp-auth-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GreenVine","download_url":"https://codeload.github.com/GreenVine/gcp-auth-util/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239788653,"owners_count":19697237,"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","cloud-run","google-cloud-platform","service-account","token"],"created_at":"2024-11-08T03:36:04.395Z","updated_at":"2026-02-03T23:30:18.261Z","avatar_url":"https://github.com/GreenVine.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gcp-auth-util\n\nThis is a utility library that requests short-lived tokens for [GCP](https://cloud.google.com) [Service Accounts](https://cloud.google.com/iam/docs/service-accounts). Command line version is also available as a standalone utility tool.\n\n## Installation\n\n`go get -u github.com/GreenVine/gcp-auth-util/auth`\n\n## Usage\n\n### As a Library\n\nBuild a `TokenRequestOptions` with appropriate settings, then retrieve the token by authenticating with service account credentials.\n\nTo request an ID token, provide `TargetAudience` and set `UseIDToken` to `true`:\n\n```go\nimport \"github.com/GreenVine/gcp-auth-util/auth\"\n\noptions := \u0026auth.TokenRequestOptions{\n    Audience:       \"https://oauth2.googleapis.com/token\", // Audience for the token\n    Expires:        3600, // Token expiry (in seconds)\n    TargetAudience: \"https://myapp.example.com\", // Target audience for the token\n    TokenURL:       \"https://oauth2.googleapis.com/token\", // OAuth2 endpoint\n    UseIDToken:     true, // true: request an ID token; false: request an access token\n}\n```\n\nTo request an access token instead, provide at least one scope and set `UseIDToken` to `false`:\n\n```go\noptions := \u0026auth.TokenRequestOptions{\n    // ...\n    Scopes:         []string{ // List of scopes\n        \"https://www.googleapis.com/auth/userinfo.email\",\n    },\n    // ...\n    UseIDToken:     false,\n}\n```\n\nThen authenticate by a service account and request a token:\n\n```go\n// Pass credentials via JSON file\ntoken, err := auth.GetTokenByServiceAccountFile(context.Background(), \"/path/to/service-account.json\", options)\n\n// Pass credentials via Base64-encoded contents\ntoken, err := auth.GetTokenByServiceAccountFile(context.Background(), []byte(\"base64-encoded-json-file-contents\"), options)\n\n// Print the token\nfmt.Println(token.AccessToken)\n```\n\n### As a Command Line Tool\n\nBuild the project with: `go build -o gau -ldflags=\"-s -w\"`, where `gau` is the resulting binary.\n\n#### CLI Options\n\n```\n-audience string\n    Token audience (default \"https://oauth2.googleapis.com/token\")\n-auth-source string\n    Authentication source: service-account (default \"service-account\")\n-credentials string\n    Base64-encoded credentials or path to the file\n-expires duration\n    Token expiry (in seconds) (default 1h0m0s)\n-scopes value\n    One or more scopes\n-target-audience string\n    Target audience\n-timeout duration\n    Operation timeout (in seconds) (default 15s)\n-token-type string\n    Token type: id, access\n-token-url string\n    OAuth2 authentication endpoint (default \"https://oauth2.googleapis.com/token\")\n```\n\n#### CLI Examples\n\n1. Request a 5-min-long ID token, authenticate by JSON file:\n\n    `gau -credentials /path/to/service-account.json -token-type id -expires 300 -target-audience \"https://myapp.example.com\"`\n\n2. Request an access token, authenticate by Base64-encoded credentials:\n\n    `gau -credentials \"base64-encoded\" -token-type access -scopes https://www.googleapis.com/auth/userinfo.email -scopes https://example.com/another-scope`\n\n## License\nGNU General Public License v3.0 or later\n\nSee [COPYING](COPYING) to see the full text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreenvine%2Fgcp-auth-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreenvine%2Fgcp-auth-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreenvine%2Fgcp-auth-util/lists"}