{"id":22572754,"url":"https://github.com/dmfed/yauth","last_synced_at":"2025-03-28T14:44:59.367Z","repository":{"id":57616899,"uuid":"382925790","full_name":"dmfed/yauth","owner":"dmfed","description":"Basic implementation of Yandex OAuth API allowing console-only apps to request authorization","archived":false,"fork":false,"pushed_at":"2021-09-03T06:23:06.000Z","size":14,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T15:13:48.759Z","etag":null,"topics":["go","library","oauth","terminal-based","yandex-api","yandex-oauth"],"latest_commit_sha":null,"homepage":"","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/dmfed.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":"2021-07-04T18:49:11.000Z","updated_at":"2024-03-03T09:55:13.000Z","dependencies_parsed_at":"2022-08-29T05:31:23.348Z","dependency_job_id":null,"html_url":"https://github.com/dmfed/yauth","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmfed%2Fyauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmfed%2Fyauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmfed%2Fyauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmfed%2Fyauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmfed","download_url":"https://codeload.github.com/dmfed/yauth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246049618,"owners_count":20715510,"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","library","oauth","terminal-based","yandex-api","yandex-oauth"],"created_at":"2024-12-08T02:11:44.428Z","updated_at":"2025-03-28T14:44:59.350Z","avatar_url":"https://github.com/dmfed.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yandex authentication with OAuth API \nThis library implements one of ways to obtain access token used to access user data in various Yandex services (for example to access Disk REST API) from Yandex OAuth API.\n\nA detailed description of implemented way to obtain access token is available here: https://yandex.com/dev/oauth/doc/dg/reference/simple-input-client.html#simple-input-client\n\nInteraction with user is handled in terminal, so the library is suitable for use in console-only applications. \n\nFirst you need to register your application at https://oauth.yandex.ru to receive credentials and define\ndefault scope of permissions that will be requested from user.\n\n## Usage\n```go\nimport \"github.com/dmfed/yauth\"\n```\n\nUse the credentials received when registering your app to create yauth.Application as follows:\n\n```go\napp, err := yauth.NewApp(\"your_client_id\", \"your_secret\")\n```\n\nApplication can be saved to disk and reused later:\n\n```go \napp.SaveToFile(\"./myapp.json\")\n\napp, err := yauth.OpenApp(\"./myapp.json\")\n```\nApplication then can be used to request user authorization as follows:\n\n```go\ntoken, err := app.RequestUserAuthorization()\n```\nThe app then prints instructions for user to Stdout and starts polling \nYandex OAuth API to check whether the user has authorized your application. \n\nTo authorize you app the user needs to visit https://ya.ru/device and enter the device code that was printed in terminal. \nThe actual link printed to user may differ, because Yandex API returns the URL that needs to be visited. \n\nIf authorization was successful the app returns AuthToken.\n\n## Token\n\nThe Token is defined as follows:\n\n```go\n// Token holds all values nececcary to access\n// Yandex services using Yandex OAuth.\ntype Token struct {\n\t// Access field contains the actual access token\n\tAccess string `json:\"access_token,omitempty\"`\n\t// Refresh field contains refresh token that\n\t// can be used to update access token\n\tRefresh string `json:\"refresh_token,omitempty\"`\n\t// Expiry holds token expiration time\n\tExpiry time.Time `json:\"token_expires,omitempty\"`\n}\n\n```\nWhat you really need to access user's data with the application that user has authorized is the **access token stored in Access field**.\n\nToken can be saved to and loaded from disk as follows:\n\n```go\nerr = token.SaveToFile(\"mytoken.json\")\nif err != nil {\n\tfmt.Println(\"error saving token to file:\", err)\n}\ntoken, err := yauth.OpenToken(\"mytoken.json\")\n```\n\nRefresh token value stored in Refresh field and can be used to update access token.\n\n```go\n// skipping error checks here for brevity\napp, _ := yauth.OpenApp(\"./myapp.json\")\ntoken, _ := yauth.OpenToken(\"./mytoken.json\")\nnewtoken, err := app.Refresh(token.Refresh)\nif err == nil {\n    newtoken.SaveToFile(\"mytoken.json\")\n}\n```\n\nExample cli app can be found in **example** directory of the repository.\n\nAny suggestions are most welcome. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmfed%2Fyauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmfed%2Fyauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmfed%2Fyauth/lists"}