{"id":13507427,"url":"https://github.com/chrislaskey/oauth2_github","last_synced_at":"2025-07-29T10:33:22.842Z","repository":{"id":57530227,"uuid":"103594687","full_name":"chrislaskey/oauth2_github","owner":"chrislaskey","description":"A GitHub OAuth2 Provider for Elixir","archived":false,"fork":false,"pushed_at":"2017-09-15T00:46:29.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-05T03:28:14.474Z","etag":null,"topics":["authentication","elixir","github","oauth2"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","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/chrislaskey.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-09-15T00:20:11.000Z","updated_at":"2018-01-27T11:16:00.000Z","dependencies_parsed_at":"2022-09-10T04:24:01.280Z","dependency_job_id":null,"html_url":"https://github.com/chrislaskey/oauth2_github","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chrislaskey/oauth2_github","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrislaskey%2Foauth2_github","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrislaskey%2Foauth2_github/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrislaskey%2Foauth2_github/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrislaskey%2Foauth2_github/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrislaskey","download_url":"https://codeload.github.com/chrislaskey/oauth2_github/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrislaskey%2Foauth2_github/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267670526,"owners_count":24125159,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"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":["authentication","elixir","github","oauth2"],"created_at":"2024-08-01T02:00:33.360Z","updated_at":"2025-07-29T10:33:17.826Z","avatar_url":"https://github.com/chrislaskey.png","language":"Elixir","funding_links":[],"categories":["Authentication"],"sub_categories":[],"readme":"# OAuth2 GitHub\n\n\u003e A GitHub OAuth2 Provider for Elixir\n\n[![Build Status](https://travis-ci.org/chrislaskey/oauth2_github.svg?branch=master)](https://travis-ci.org/chrislaskey/oauth2_github)\n\nOAuth2 GitHub is convenience library built on top of [`oauth2`](https://hex.pm/packages/oauth2). It adds GitHub specific functions to interact with GitHub endpoints using OAuth2.\n\n## Installation\n\n```elixir\n# mix.exs\n\ndef application do\n  # Add the application to your list of applications.\n  # This will ensure that it will be included in a release.\n  [applications: [:logger, :oauth2_github]]\nend\n\ndefp deps do\n  # Add the dependency\n  [{:oauth2_github, \"~\u003e 0.1\"}]\nend\n```\n\n## Authenticating a User\n\n\u003e For an easy-to-use, end-to-end solution enabling users to log in with GitHub see [`ueberauth/ueberauth_github`](https://github.com/ueberauth/ueberauth_github)\n\nOne common use-case is authenticating a user's identify. The `get_user!` function wraps two actions into one - exchanging the callback code for a short-lived access token and using the access token to return user data:\n\n```elixir\nalias OAuth2.Provider.GitHub\n\nGitHub.get_user!([code: \"\u003ccallback-code\u003e\"], [redirect_uri: \"...\"])\n```\n\nWhen successful, it returns the user data:\n\n```elixir\n{:ok, %{\"collaborators\" =\u003e 0, \"two_factor_authentication\" =\u003e true, \"company\" =\u003e nil, \"bio\" =\u003e nil, \"following\" =\u003e 0, \"followers_url\" =\u003e \"https://api.github.com/users/example/followers\", \"public_gists\" =\u003e 0, \"id\" =\u003e 1, \"avatar_url\" =\u003e \"https://avatars1.githubusercontent.com/u/1?v=4\", \"events_url\" =\u003e \"https://api.github.com/users/example/events{/privacy}\", \"starred_url\" =\u003e \"https://api.github.com/users/example/starred{/owner}{/repo}\", \"emails\" =\u003e [%{\"email\" =\u003e \"chris.laskey@gmail.com\", \"primary\" =\u003e true, \"verified\" =\u003e true, \"visibility\" =\u003e \"public\"}, %{\"email\" =\u003e \"1@example.com\", \"primary\" =\u003e false, \"verified\" =\u003e true, \"visibility\" =\u003e nil}, %{\"email\" =\u003e \"2@example.com\", \"primary\" =\u003e false, \"verified\" =\u003e true, \"visibility\" =\u003e nil}, %{\"email\" =\u003e \"3@example.com\", \"primary\" =\u003e false, \"verified\" =\u003e false, \"visibility\" =\u003e nil}], \"private_gists\" =\u003e 0, \"blog\" =\u003e \"http://example.com\", \"subscriptions_url\" =\u003e \"https://api.github.com/users/example/subscriptions\", \"type\" =\u003e \"User\", \"disk_usage\" =\u003e 517040, \"site_admin\" =\u003e false, \"owned_private_repos\" =\u003e 0, \"public_repos\" =\u003e 75, \"location\" =\u003e \"Moon\", \"hireable\" =\u003e nil, \"created_at\" =\u003e \"2016-10-30T22:30:53Z\", \"name\" =\u003e \"John Smith\", \"organizations_url\" =\u003e \"https://api.github.com/users/example/orgs\", \"gists_url\" =\u003e \"https://api.github.com/users/example/gists{/gist_id}\", \"following_url\" =\u003e \"https://api.github.com/users/example/following{/other_user}\", \"url\" =\u003e \"https://api.github.com/users/example\", \"email\" =\u003e \"contact@example.com\", \"login\" =\u003e \"example\", \"html_url\" =\u003e \"https://github.com/example\", \"gravatar_id\" =\u003e \"\", \"received_events_url\" =\u003e \"https://api.github.com/users/example/received_events\", \"repos_url\" =\u003e \"https://api.github.com/users/example/repos\", \"plan\" =\u003e %{\"collaborators\" =\u003e 0, \"name\" =\u003e \"free\", \"private_repos\" =\u003e 0, \"space\" =\u003e 32976562499}, \"followers\" =\u003e 0, \"updated_at\" =\u003e \"2017-01-03T01:00:40Z\", \"total_private_repos\" =\u003e 0}}\n```\n\n## Returning an Access Token\n\nA valid access token can be used to make multiple requests to GitHub. The callback code can be exchanged for an access token using `get_token!`:\n\n```elixir\nalias OAuth2.Provider.GitHub\n\nclient = GitHub.get_token!([code: \"\u003ccallback-code\u003e\"], [redirect_uri: \"...\"])\n```\n\nWhen successful, it will return a valid `OAuth2.Client`:\n\n```\n%OAuth2.Client{authorize_url: \"https://github.com/login/oauth/authorize\", client_id: \"\u003c...\u003e\", client_secret: \"\u003c...\u003e\", headers: [], params: %{}, redirect_uri: \"http://localhost:3000/login/github/callback\", ref: nil, request_opts: [], site: \"https://api.github.com\", strategy: OAuth2.Provider.GitHub, token: %OAuth2.AccessToken{access_token: \"38aac97adc9722c62272bf521a38e4f0cd7423fa\", expires_at: nil, other_params: %{\"scope\" =\u003e \"user\"}, refresh_token: nil, token_type: \"Bearer\"}, token_method: :post, token_url: \"https://github.com/login/oauth/access_token\"}\n```\n\n**Note:** The access token is kept under the client's `token` key.\n\n## Using a Valid Client\n\nA valid client with an access token can then be passed into endpoint specific functions. For example, to return user data using a `client` with a valid access token:\n\n```elixir\nalias OAuth2.Provider.GitHub\n\n{:ok, user} = GitHub.get_user(client)\n```\n\nWhen successful, it will return the same user information:\n\n```elixir\n%{\"collaborators\" =\u003e 0, \"two_factor_authentication\" =\u003e true, \"company\" =\u003e nil, \"bio\" =\u003e nil, \"following\" =\u003e 0, \"followers_url\" =\u003e \"https://api.github.com/users/example/followers\", \"public_gists\" =\u003e 0, \"id\" =\u003e 1, \"avatar_url\" =\u003e \"https://avatars1.githubusercontent.com/u/1?v=4\", \"events_url\" =\u003e \"https://api.github.com/users/example/events{/privacy}\", \"starred_url\" =\u003e \"https://api.github.com/users/example/starred{/owner}{/repo}\", \"emails\" =\u003e [%{\"email\" =\u003e \"chris.laskey@gmail.com\", \"primary\" =\u003e true, \"verified\" =\u003e true, \"visibility\" =\u003e \"public\"}, %{\"email\" =\u003e \"1@example.com\", \"primary\" =\u003e false, \"verified\" =\u003e true, \"visibility\" =\u003e nil}, %{\"email\" =\u003e \"2@example.com\", \"primary\" =\u003e false, \"verified\" =\u003e true, \"visibility\" =\u003e nil}, %{\"email\" =\u003e \"3@example.com\", \"primary\" =\u003e false, \"verified\" =\u003e false, \"visibility\" =\u003e nil}], \"private_gists\" =\u003e 0, \"blog\" =\u003e \"http://example.com\", \"subscriptions_url\" =\u003e \"https://api.github.com/users/example/subscriptions\", \"type\" =\u003e \"User\", \"disk_usage\" =\u003e 517040, \"site_admin\" =\u003e false, \"owned_private_repos\" =\u003e 0, \"public_repos\" =\u003e 75, \"location\" =\u003e \"Moon\", \"hireable\" =\u003e nil, \"created_at\" =\u003e \"2016-10-30T22:30:53Z\", \"name\" =\u003e \"John Smith\", \"organizations_url\" =\u003e \"https://api.github.com/users/example/orgs\", \"gists_url\" =\u003e \"https://api.github.com/users/example/gists{/gist_id}\", \"following_url\" =\u003e \"https://api.github.com/users/example/following{/other_user}\", \"url\" =\u003e \"https://api.github.com/users/example\", \"email\" =\u003e \"contact@example.com\", \"login\" =\u003e \"example\", \"html_url\" =\u003e \"https://github.com/example\", \"gravatar_id\" =\u003e \"\", \"received_events_url\" =\u003e \"https://api.github.com/users/example/received_events\", \"repos_url\" =\u003e \"https://api.github.com/users/example/repos\", \"plan\" =\u003e %{\"collaborators\" =\u003e 0, \"name\" =\u003e \"free\", \"private_repos\" =\u003e 0, \"space\" =\u003e 32976562499}, \"followers\" =\u003e 0, \"updated_at\" =\u003e \"2017-01-03T01:00:40Z\", \"total_private_repos\" =\u003e 0}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrislaskey%2Foauth2_github","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrislaskey%2Foauth2_github","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrislaskey%2Foauth2_github/lists"}