{"id":22619135,"url":"https://github.com/caneroj1/hauth","last_synced_at":"2025-03-29T01:41:23.361Z","repository":{"id":150932118,"uuid":"97272618","full_name":"caneroj1/hauth","owner":"caneroj1","description":"Experiments in jwt authentication in haskell","archived":false,"fork":false,"pushed_at":"2017-07-14T21:16:56.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-03T11:47:55.199Z","etag":null,"topics":["haskell","jwt","jwt-authentication"],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caneroj1.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-14T21:04:33.000Z","updated_at":"2023-03-05T01:09:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"48200878-f421-423f-ba3c-4344e383ad1c","html_url":"https://github.com/caneroj1/hauth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caneroj1%2Fhauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caneroj1%2Fhauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caneroj1%2Fhauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caneroj1%2Fhauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caneroj1","download_url":"https://codeload.github.com/caneroj1/hauth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246126662,"owners_count":20727594,"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":["haskell","jwt","jwt-authentication"],"created_at":"2024-12-08T21:14:00.052Z","updated_at":"2025-03-29T01:41:23.340Z","avatar_url":"https://github.com/caneroj1.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hauth\n\n## Notes\n\nMost definitely not production ready. There are a few things that still need to happen _if_ this will ever make it there.\n\n* Create the encryption key in a place where it can be retrieved. Currently, a new encryption key is created whenever the application is started.\n* Maybe integrate with other user-management systems in haskell?\n* Maybe store each jwt in a db where they can be attached to user IDs so they can be expired.\n* Use lens for managementing configuration state?\n* Extend the authentication to support other application-specific claims?\n* More?\n\n## Usage\n\n```haskell\n\n-- Basic authentication config for the application.\nauthenticationConfig :: AuthenticationConfig\nauthenticationConfig = mkConfigWithAppAndCookieName \"TestAppAPI\" \"\"\n\n-- We don't want to allow cookie-based authentication.\n-- The app will now expect jwt tokens in the Authorization header as \"Bearer \u003cjwt\u003e\"\ndisableCookies :: AuthenticationConfig -\u003e AuthenticationConfig\ndisableCookies ac = ac { cookieConfig = (cookieConfig ac) { cookieDisabled = True } }\n\n-- Start the app\n----------------\n-- 1.\n-- With our configuration settings, build the authentication machinery for the\n-- application. This returns a tuple of functions.\n-- The first function is the authentication guard and can be used to secure\n-- routes. It returns a UUID if all authentication is successful.\n----------------\n-- 2.\n-- Use the `authGuard` function to guard this route. It will look for a jwt,-- decode it, make sure it is valid and not expired, and return the UUID\n--from the token.\n----------------\n-- 3.\n-- Use the `authenticator` function to authenticate a \"user\" and return a\n-- jwt. The `authenticator` accepts a UUID, so presumably this happens after\n-- username/password authentication gets the UUID. The jwt returned from the\n-- `authenticator` will be checked in the `authGuard`.\nmain :: IO ()\nmain = do\n  -- 1.\n  (authGuard, authenticator) \u003c- buildAuthenticatorPair $ disableCookies authenticationConfig\n  scotty 3000 $ do\n    middleware logStdoutDev\n    get \"/\" $ do\n      -- 2.\n      uuid \u003c- authGuard\n      text (\"Successfully authenticated: \" `T.append` T.fromStrict (toText uuid))\n    post \"/v1/authenticate\" $ do\n      uuid \u003c- liftIO nextRandom\n      -- 3\n      authenticator uuid\n\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaneroj1%2Fhauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaneroj1%2Fhauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaneroj1%2Fhauth/lists"}