{"id":13507425,"url":"https://github.com/chrislaskey/oauth2_facebook","last_synced_at":"2025-04-19T12:36:21.520Z","repository":{"id":62430150,"uuid":"100137659","full_name":"chrislaskey/oauth2_facebook","owner":"chrislaskey","description":"A Facebook OAuth2 Provider for Elixir","archived":false,"fork":false,"pushed_at":"2017-08-15T15:32:06.000Z","size":19,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-14T09:14:08.434Z","etag":null,"topics":["authentication","elixir","facebook","facebook-graph","oauth2"],"latest_commit_sha":null,"homepage":"","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-08-12T21:02:46.000Z","updated_at":"2018-01-31T00:59:57.000Z","dependencies_parsed_at":"2022-11-01T20:08:17.374Z","dependency_job_id":null,"html_url":"https://github.com/chrislaskey/oauth2_facebook","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrislaskey%2Foauth2_facebook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrislaskey%2Foauth2_facebook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrislaskey%2Foauth2_facebook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrislaskey%2Foauth2_facebook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrislaskey","download_url":"https://codeload.github.com/chrislaskey/oauth2_facebook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224953366,"owners_count":17397689,"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","elixir","facebook","facebook-graph","oauth2"],"created_at":"2024-08-01T02:00:33.333Z","updated_at":"2024-11-16T18:20:23.731Z","avatar_url":"https://github.com/chrislaskey.png","language":"Elixir","funding_links":[],"categories":["Authentication"],"sub_categories":[],"readme":"# OAuth2 Facebook\n\n\u003e A Facebook OAuth2 Provider for Elixir\n\n[![Build Status](https://travis-ci.org/chrislaskey/oauth2_facebook.svg?branch=master)](https://travis-ci.org/chrislaskey/oauth2_facebook)\n[![Coverage Status](https://coveralls.io/repos/github/chrislaskey/oauth2_facebook/badge.svg?branch=master)](https://coveralls.io/github/chrislaskey/oauth2_facebook?branch=master)\n\nOAuth2 Facebook is convenience library built on top of [`oauth2`](https://hex.pm/packages/oauth2). It adds Facebook specific functions to interact with the Facebook Graph 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_facebook]]\nend\n\ndefp deps do\n  # Add the dependency\n  [{:oauth2_facebook, \"~\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 Facebook see [`ueberauth/ueberauth_facebook`](https://github.com/ueberauth/ueberauth_facebook)\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.Facebook\n\nFacebook.get_user!([code: \"\u003ccallback-code\u003e\"], [redirect_uri: \"...\"])\n```\n\nWhen successful, it returns the user data:\n\n```elixir\n{:ok, %{\"email\" =\u003e \"user@gmail.com\", \"gender\" =\u003e \"male\", \"id\" =\u003e \"101\", \"link\" =\u003e \"https://www.facebook.com/app_scoped_user_id/101/\", \"locale\" =\u003e \"en_US\", \"name\" =\u003e \"user\", \"timezone\" =\u003e -4, \"updated_time\" =\u003e \"2015-06-05T14:59:20+0000\", \"verified\" =\u003e true}}\n```\n\n## Returning an Access Token\n\nA valid access token can be used to make multiple requests to the Facebook Graph. The callback code can be exchanged for an access token using `get_token!`:\n\n```elixir\nalias OAuth2.Provider.Facebook\n\nclient = Facebook.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://www.facebook.com/dialog/oauth\", client_id: \"\u003c...\u003e\", client_secret: \"\u003c...\u003e\", headers: [], params: %{}, redirect_uri: \"http://localhost:3000/login/facebook/callback\", ref: nil, request_opts: [], site: \"https://graph.facebook.com\", strategy: OAuth2.Provider.Facebook, token: %OAuth2.AccessToken{access_token: \"EAABw0PjpdjcBAMDUjWQtZApFV2nFJfhIUWaw3z8MSbi92fVooa2BNBdZBeRaxMcHO94zdmncoFuZBvQQdj0cmXosa8kAZCx7wtlSR5ByT2etOhURZCNjs9DDFfpU456Gk8f0tvzmtYsiMstSKkh69kIzSVOeQIx8TPQOLpXHnRCARNXCiiB1Y\", expires_at: 1507926168, other_params: %{}, refresh_token: nil, token_type: \"Bearer\"}, token_method: :get, token_url: \"/v2.8/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.Facebook\n\n{:ok, user} = Facebook.get_user(client)\n```\n\nWhen successful, it will return the same user information:\n\n```elixir\n%{\"email\" =\u003e \"user@gmail.com\", \"gender\" =\u003e \"male\", \"id\" =\u003e \"101\", \"link\" =\u003e \"https://www.facebook.com/app_scoped_user_id/101/\", \"locale\" =\u003e \"en_US\", \"name\" =\u003e \"user\", \"timezone\" =\u003e -4, \"updated_time\" =\u003e \"2015-06-05T14:59:20+0000\", \"verified\" =\u003e true}\n```\n\n## Filtering User fields\n\nBoth `get_user!` and `get_user` support passing custom query params. These can be used to filter the returned attributes:\n\n```elixir\nalias OAuth2.Provider.Facebook\n\n# Using `get_user!`\nuser = Facebook.get_user!([code: \"\u003ccallback-code\u003e\"], [redirect_uri: \"...\"], [fields: \"email,name\"])\n\n# Using `get_user`\nclient = Facebook.get_token!([code: \"\u003ccallback-code\u003e\"], [redirect_uri: \"...\"])\n{:ok, user} = Facebook.get_user(client, [fields: \"email,name\"])\n```\n\nWhen successful, will return a trimmed down user:\n\n```elixir\n%{\"email\" =\u003e \"user@gmail.com\", \"id\" =\u003e \"101\", \"name\" =\u003e \"user\"}\n```\n\n**Note:** The `id` value is always returned.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrislaskey%2Foauth2_facebook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrislaskey%2Foauth2_facebook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrislaskey%2Foauth2_facebook/lists"}