{"id":16469986,"url":"https://github.com/alexzeitler/cognito-fsharp-giraffe-react-sample","last_synced_at":"2025-08-09T17:17:24.274Z","repository":{"id":54985550,"uuid":"329785513","full_name":"AlexZeitler/cognito-fsharp-giraffe-react-sample","owner":"AlexZeitler","description":"An example how to use AWS Cognito (via CDK) with F# Giraffe and React","archived":false,"fork":false,"pushed_at":"2021-01-17T19:17:57.000Z","size":1595,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-08T09:47:49.994Z","etag":null,"topics":["aws","aws-cdk","cognito","cognito-example","fsharp","fsharp-samples","giraffe","openid-connect","openid-sample","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/AlexZeitler.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-01-15T02:13:59.000Z","updated_at":"2021-12-28T10:38:34.000Z","dependencies_parsed_at":"2022-08-14T08:10:50.286Z","dependency_job_id":null,"html_url":"https://github.com/AlexZeitler/cognito-fsharp-giraffe-react-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AlexZeitler/cognito-fsharp-giraffe-react-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexZeitler%2Fcognito-fsharp-giraffe-react-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexZeitler%2Fcognito-fsharp-giraffe-react-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexZeitler%2Fcognito-fsharp-giraffe-react-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexZeitler%2Fcognito-fsharp-giraffe-react-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexZeitler","download_url":"https://codeload.github.com/AlexZeitler/cognito-fsharp-giraffe-react-sample/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexZeitler%2Fcognito-fsharp-giraffe-react-sample/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269606692,"owners_count":24446239,"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-08-09T02:00:10.424Z","response_time":111,"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":["aws","aws-cdk","cognito","cognito-example","fsharp","fsharp-samples","giraffe","openid-connect","openid-sample","react"],"created_at":"2024-10-11T12:09:27.728Z","updated_at":"2025-08-09T17:17:24.231Z","avatar_url":"https://github.com/AlexZeitler.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS Cognito (via CDK) F# Giraffe React PKCE flow sample\n\nThis sample shows how to use [AWS Cognito](https://aws.amazon.com/cognito/) (deployed via [AWS CDK](https://aws.amazon.com/cdk/)) together with an F# [Giraffe](https://github.com/giraffe-fsharp/Giraffe) API and a React application with  Authorization Code Grant (PKCE).\n\n## Setup\n\nClone this repository.\n\n### Cognito\n\n#### Install / configure AWS CDK\n\n```bash\nnpm install -g aws-cdk\n```\n\n* [Configure a user profile for CDK](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html)\n* [Bootstrap AWS CDK](https://docs.aws.amazon.com/de_de/cdk/latest/guide/bootstrapping.html) (this may cause costs!)\n\n#### Configure Cognito Userpool\n\nEdit `src/cognito/lib/config.json`:\n\n```json\n{\n  \"userpoolName\": \"sample-user-pool\",\n  \"scopeName\": \"api\",\n  \"resourceServerName\": \"giraffe-server\",\n  \"resourceServerIdentifier\": \"giraffe-server\",\n  \"clientName\": \"react-client\",\n  \"domainPrefix\": \"giraffe-sample\"\n}\n```\n\n#### Deploy Cognito\n\n```bash\ncd src/cognito\nyarn\ncdk deploy\n```\n\nYour output should look like this:\n\n```bash\nCognitoStack: deploying...\n\n ✅  CognitoStack\n\nOutputs:\nCognitoStack.domain = giraffe-sample\nCognitoStack.reactClientId = 3ot29hu8k3cbikij2jat97sqou\nCognitoStack.scopeName = giraffe-server/api\nCognitoStack.userpoolId = eu-central-1_rypunXn4M\n```\n\nMake sure to grab the Information listed below \"Outputs\" - otherwise you'll have to lookup them in the AWS Cognito Console.\n\n#### Create a Cognito User\n\n- [Add a AWS Cognito User](https://docs.aws.amazon.com/cognito/latest/developerguide/how-to-create-user-accounts.html)\n\nSample:\n\n![](./assets/img/create-user.png)\n\n\n### Giraffe API\n\n#### Configure the Giraffe API\n\nChange the settings in the `Config` module in `src/SampleAPI/Program.fs`:\n\n```fsharp\nmodule Config =\n  let region = \"eu-central-1\" // your AWS region\n  let userPoolId = \"eu-central-1_rypunXn4M\" // CognitoStack.userpoolId\n  let clientId = \"3ot29hu8k3cbikij2jat97sqou\" // CognitoStack.reactClientId\n  let scopeName = \"giraffe-server/api\" // CognitoStack.scopeName\n  let clientUri = \"http://localhost:3000\"\n```\n\n#### Start the Giraffe API\n\n```bash\ndotnet run --no-restore\n```\n\nYour API should now be listening:\n\n```bash\ninfo: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[62]\n      User profile is available. Using '/Users/alexzeitler/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.\ninfo: Microsoft.Hosting.Lifetime[0]\n      Now listening on: http://localhost:5000\ninfo: Microsoft.Hosting.Lifetime[0]\n      Now listening on: https://localhost:5001\ninfo: Microsoft.Hosting.Lifetime[0]\n      Application started. Press Ctrl+C to shut down.\n```\n\n### React UI\n\n#### Configure the React UI\n\nEdit `src/ui/src/config/app-config.json`:\n\n```json5\n{\n    \"region\": \"eu-central-1\", // your AWS region\n    \"userPool\": \"eu-central-1_rypunXn4M\", // CognitoStack.userpoolId\n    \"userPoolBaseUri\": \"https://giraffe-sample.auth.eu-central-1.amazoncognito.com\", // https://${CognitoStack.domain}.auth.${AWS_REGION}.amazoncognito.com\n    \"clientId\": \"3ot29hu8k3cbikij2jat97sqou\", // CognitoStack.reactClientId\n    \"callbackUri\": \"http://localhost:3000/callback\",\n    \"signoutUri\": \"http://localhost:3000\",\n    \"tokenScopes\": [\n        \"openid\",\n        \"email\",\n        \"profile\",\n        \"giraffe-server/api\" // CognitoStack.scopeName              \n    ],\n    \"apiUri\": \"https://localhost:5001\"\n}\n```\n\n#### Start the React UI\n\n```bash\ncd src/ui\nyarn start\n```\n\nYour browser should show this:\n\n![](./assets/img/ui-not-logged-in.png)\n\n#### Login\n\nClick the \"Sign in\" link in your UI:\n\n![](./assets/img/ui-not-logged-in.png)\n\nEnter your credentials:\n\n\n![](./assets/img/login.png)\n\nIf everything went well, you'll see this screen:\n\n![](./assets/img/login-and-api-call-successful.png)\n\n## Credits\n\nThe UI is based on https://github.com/arronharden/cognito-demo-ui.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexzeitler%2Fcognito-fsharp-giraffe-react-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexzeitler%2Fcognito-fsharp-giraffe-react-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexzeitler%2Fcognito-fsharp-giraffe-react-sample/lists"}