{"id":16541059,"url":"https://github.com/linki/go-tokens","last_synced_at":"2026-07-22T13:32:27.436Z","repository":{"id":66308461,"uuid":"60205488","full_name":"linki/go-tokens","owner":"linki","description":"Go library to manage OAuth tokens","archived":false,"fork":false,"pushed_at":"2016-06-01T21:42:37.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-22T13:57:01.680Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linki.png","metadata":{"files":{"readme":"README.rst","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":"2016-06-01T19:38:00.000Z","updated_at":"2018-04-08T11:48:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"f633e7a4-522a-4652-80cb-4edb9c44537c","html_url":"https://github.com/linki/go-tokens","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/linki/go-tokens","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linki%2Fgo-tokens","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linki%2Fgo-tokens/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linki%2Fgo-tokens/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linki%2Fgo-tokens/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linki","download_url":"https://codeload.github.com/linki/go-tokens/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linki%2Fgo-tokens/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35764375,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-22T02:00:06.236Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11T18:53:58.628Z","updated_at":"2026-07-22T13:32:27.409Z","avatar_url":"https://github.com/linki.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Go Tokens Library\n=================\n\n.. image:: https://travis-ci.org/zalando/go-tokens.svg?branch=master\n    :target: https://travis-ci.org/zalando/go-tokens\n\n.. image:: https://codecov.io/github/zalando/go-tokens/coverage.svg?branch=master\n    :target: https://codecov.io/github/zalando/go-tokens?branch=master\n\n.. image:: https://goreportcard.com/badge/github.com/zalando/go-tokens\n    :target: https://goreportcard.com/report/github.com/zalando/go-tokens\n\n.. image:: https://godoc.org/github.com/zalando/go-tokens?status.svg\n    :target: https://godoc.org/github.com/zalando/go-tokens\n\nThis is a library very similar to `tokens`_ and `python-tokens`_.\n\nIn a nutshell, you provide the OAuth2 token endpoint and which tokens and scopes to have managed.\n \nThe library can use any custom credentials provider and it will make sure that the managed tokens are always\nvalid by refreshing them before they expire.\n\nCredentials Provider\n--------------------\n\nThe library currently contains implementations of the ``user.CredentialsProvider`` and the ``client.CredentialsProvider``\nthat you can use out of the box. The simplest providers just returns some static values used on creation. The other\nproviders fetch credentials from JSON files (user.json and client.json) from a folder defined in the\n``CREDENTIALS_DIR`` environment variable.\n\nYou can easily use your own credential providers.\n\nUser Credentials\n~~~~~~~~~~~~~~~~\n\nUser credentials are, very simply, a username and a password. Any type that implements the ``user.Credentials`` should\nbe able to provide them. The ``user.CredentialsProvider`` is the interface to implement for any custom type that is\nable to provide ``user.Credentials``.\n\nFor a simple example, check the ``user/static.go`` file.\n\nClient Credentials\n~~~~~~~~~~~~~~~~~~\n\nClient credentials are very similar to the user credentials. It consists of a client ID and client secret. Any type\nthat implements the ``client.Credentials`` should be able to provide them. The ``client.CredentialsProvider`` is the\ninterface to implement for any custom type that is able to provide ``client.Credentials``.\n\nFor a simple example, check the ``client/static.go`` file.\n\nUsers Guide\n-----------\n\n.. code-block:: go\n\n    url := \"https://example.com/oauth2/access_token\"\n\n    // You can manage multiple tokens with different scopes\n\treqs := []tokens.ManagementRequest{\n\t\ttokens.NewPasswordRequest(\"test1\", \"foo.read\"),\n\t\ttokens.NewPasswordRequest(\"test2\", \"user.email\", \"user.name\"),\n\t}\n\n\t// Manager creation tries to obtain all tokens synchronously initially\n\ttokensManager, err := tokens.Manage(url, reqs)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// You can use any of the above tokens for as long as you want\n\tfor {\n\t\taccessToken, err := tokensManager.Get(\"test1\") // or \"test2\"\n\t\tif err != nil {\n\t\t\tlog.Println(err)\n\t\t} else {\n\t\t\t// Do something with accessToken\n\t\t}\n\t}\n\nThe previous example would create a token manager using the JSON files credentials providers and a refresh threshold of 60% of the token validity time.\n\nManager Options\n~~~~~~~~~~~~~~~\n\nYou can customize the behavior of the Manager with the following options:\n    \nRefreshPercentageThreshold(float64)\n    Accepts any float between 0 and 1 (exclusive) which defines the percentage of token validity when to schedule background refreshing\n\nWarningPercentageThreshold(float64)\n    Accepts any float between 0 (exclusive) and 1 (inclusive) which defines when the library starts logging warnings that tokens will, eventually expire.\n    This can happen if, for example, the background refresh is failing.\n    It should be higher than the refresh threshold.\n    \nUserCredentialsProvider(user.CredentialsProvider)\n    Accepts any user.CredentialsProvider instance that will provide user credentials for the password grant type\n    \nClientCredentialsProvider(client.CredentialsProvider)\n    Accepts any client.CredentialsProvider instance that will provide client credentials for the OAuth calls\n\n.. _tokens: https://github.com/zalando-stups/tokens\n.. _python-tokens: https://github.com/zalando-stups/python-tokens\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinki%2Fgo-tokens","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinki%2Fgo-tokens","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinki%2Fgo-tokens/lists"}