{"id":23613654,"url":"https://github.com/freckle/yesod-auth-oauth2","last_synced_at":"2025-04-08T13:07:51.675Z","repository":{"id":9506392,"uuid":"11400804","full_name":"freckle/yesod-auth-oauth2","owner":"freckle","description":"OAuth2 authentication for yesod","archived":false,"fork":false,"pushed_at":"2025-03-28T22:07:22.000Z","size":526,"stargazers_count":70,"open_issues_count":2,"forks_count":53,"subscribers_count":34,"default_branch":"main","last_synced_at":"2025-04-01T11:07:13.995Z","etag":null,"topics":["ghvm-managed"],"latest_commit_sha":null,"homepage":"","language":"Haskell","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/freckle.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-14T09:12:20.000Z","updated_at":"2025-02-07T20:48:44.000Z","dependencies_parsed_at":"2023-02-17T10:00:32.943Z","dependency_job_id":"422214e5-7216-45a2-ac00-249427ac9e27","html_url":"https://github.com/freckle/yesod-auth-oauth2","commit_stats":{"total_commits":368,"total_committers":38,"mean_commits":9.68421052631579,"dds":0.2527173913043478,"last_synced_commit":"3c15ecd871a5b10f98123059b97e973221ff7395"},"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fyesod-auth-oauth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fyesod-auth-oauth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fyesod-auth-oauth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fyesod-auth-oauth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freckle","download_url":"https://codeload.github.com/freckle/yesod-auth-oauth2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247847611,"owners_count":21006100,"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":["ghvm-managed"],"created_at":"2024-12-27T17:18:37.326Z","updated_at":"2025-04-08T13:07:51.641Z","avatar_url":"https://github.com/freckle.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yesod.Auth.OAuth2\n\n[![Hackage](https://img.shields.io/hackage/v/yesod-auth-oauth2.svg?style=flat)](https://hackage.haskell.org/package/yesod-auth-oauth2)\n[![Stackage Nightly](http://stackage.org/package/yesod-auth-oauth2/badge/nightly)](http://stackage.org/nightly/package/yesod-auth-oauth2)\n[![Stackage LTS](http://stackage.org/package/yesod-auth-oauth2/badge/lts)](http://stackage.org/lts/package/yesod-auth-oauth2)\n[![CI](https://github.com/freckle/yesod-auth-oauth2/actions/workflows/ci.yml/badge.svg)](https://github.com/pbrisbin/freckle/yesod-auth-oauth2/workflows/ci.yml)\n\nOAuth2 `AuthPlugin`s for Yesod.\n\n## Usage\n\n```hs\nimport Yesod.Auth\nimport Yesod.Auth.OAuth2.GitHub\n\ninstance YesodAuth App where\n    -- ...\n\n    authPlugins _ = [oauth2GitHub clientId clientSecret]\n\nclientId :: Text\nclientId = \"...\"\n\nclientSecret :: Text\nclientSecret = \"...\"\n```\n\nSome plugins, such as GitHub and Slack, have scoped functions for requesting\nadditional information:\n\n```hs\noauth2SlackScoped [SlackBasicScope, SlackEmailScope] clientId clientSecret\n```\n\n## Working with Extra Data\n\nWe put the minimal amount of user data possible in `credsExtra` -- just enough\nto support you parsing or fetching additional data yourself.\n\nFor example, if you work with GitHub and GitHub user profiles, you likely\nalready have a model and a way to parse the `/user` response. Rather than\nduplicate all that in our library, we try to make it easy for you to re-use that\ncode yourself:\n\n```hs\nauthenticate creds = do\n    let\n        -- You can run your own FromJSON parser on the response we already have\n        eGitHubUser :: Either String GitHubUser\n        eGitHubUser = getUserResponseJSON creds\n\n        -- Avert your eyes, simplified example\n        Just accessToken = getAccessToken creds\n        Right githubUser = eGitHubUser\n\n    -- Or make followup requests using our access token\n    runGitHub accessToken $ userRepositories githubUser\n\n    -- Or store it for later\n    insert User\n        { userIdent = credsIdent creds\n        , userAccessToken = accessToken\n        }\n```\n\n**NOTE**: Avoid looking up values in `credsExtra` yourself; prefer the provided\n`get` functions. The data representation itself is no longer considered public\nAPI.\n\n## Local Providers\n\nIf we don't supply a \"Provider\" (e.g. GitHub, Google, etc) you need, you can\nwrite your own using our provided `Prelude`:\n\n```haskell\nimport Yesod.Auth.OAuth2.Prelude\n\npluginName :: Text\npluginName = \"mysite\"\n\noauth2MySite :: YesodAuth m =\u003e Text -\u003e Text -\u003e AuthPlugin m\noauth2MySite clientId clientSecret =\n    authOAuth2 pluginName oauth2 $ \\manager token -\u003e do\n        -- Fetch a profile using the manager and token, leave it a ByteString\n        userResponse \u003c- -- ...\n\n        -- Parse it to your preferred identifier, e.g. with Data.Aeson\n        userId \u003c- -- ...\n\n        -- See authGetProfile for the typical case\n\n        pure Creds\n            { credsPlugin = pluginName\n            , credsIdent = userId\n            , credsExtra = setExtra token userResponse\n            }\n  where\n    oauth2 = OAuth2\n        { oauth2ClientId = clientId\n        , oauth2ClientSecret = Just clientSecret\n        , oauth2AuthorizeEndpoint = \"https://mysite.com/oauth/authorize\"\n        , oauth2TokenEndpoint = \"https://mysite.com/oauth/token\"\n        , oauth2RedirectUri = Nothing\n        }\n```\n\nThe `Prelude` module is considered public API, though we may build something\nhigher-level that is more convenient for this use-case in the future.\n\n## Development \u0026 Tests\n\n```console\nstack setup\nstack build --dependencies-only\nstack build --pedantic --test\n```\n\nPlease also run HLint and Weeder before submitting PRs.\n\n## Example\n\nThis project includes an executable that runs a server with (almost) all\nsupported providers present.\n\nTo use:\n\n1. `cp .env.example .env` and edit in secrets for providers you wish to test\n\n   Be sure to include `http://localhost:3000/auth/page/{plugin}/callback` as a\n   valid Redirect URI when configuring the OAuth application.\n\n2. Build with the example: `stack build ... --flag yesod-auth-oauth2:example`\n3. Run the example `stack exec yesod-auth-oauth2-example`\n4. Visit the example: `$BROWSER http://localhost:3000`\n5. Click the log-in link for the provider you configured\n\nIf successful, you will be presented with a page that shows the credential and\nUser response value.\n\n---\n\n[CHANGELOG](./CHANGELOG.md) | [LICENSE](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreckle%2Fyesod-auth-oauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreckle%2Fyesod-auth-oauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreckle%2Fyesod-auth-oauth2/lists"}