{"id":20679867,"url":"https://github.com/morrys/amazon-cognito-auth-ts","last_synced_at":"2025-04-19T23:52:43.622Z","repository":{"id":57177093,"uuid":"187386604","full_name":"morrys/amazon-cognito-auth-ts","owner":"morrys","description":"The Amazon Cognito Auth SDK for TypeScript","archived":false,"fork":false,"pushed_at":"2019-05-18T18:16:23.000Z","size":115,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T23:52:38.992Z","etag":null,"topics":["authentication","aws","cognito","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/morrys.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":"2019-05-18T17:27:49.000Z","updated_at":"2025-02-24T21:08:53.000Z","dependencies_parsed_at":"2022-09-14T02:10:20.895Z","dependency_job_id":null,"html_url":"https://github.com/morrys/amazon-cognito-auth-ts","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/morrys%2Famazon-cognito-auth-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morrys%2Famazon-cognito-auth-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morrys%2Famazon-cognito-auth-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morrys%2Famazon-cognito-auth-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/morrys","download_url":"https://codeload.github.com/morrys/amazon-cognito-auth-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249830852,"owners_count":21331357,"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","aws","cognito","typescript"],"created_at":"2024-11-16T21:28:02.356Z","updated_at":"2025-04-19T23:52:43.592Z","avatar_url":"https://github.com/morrys.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Amazon Cognito Auth SDK for JavaScript\nYou can now use Amazon Cognito Auth to easily add sign-in and sign-out to your mobile and web apps. Your user pool in Amazon Cognito is a fully managed user directory that can scale to hundreds of millions of users, so you don't have to worry about building, securing, and scaling a solution to handle user management and authentication.\n\n[For more information about this new feature, see Amazon Cognito User Pools App Integration and Federation GA Release.](http://docs.aws.amazon.com/cognito/latest/developerguide/getting-started.html)\n\n# Introduction\nThe Amazon Cognito Auth SDK for JavaScript simplifies adding sign-up, sign-in with user profile functionality to web apps.\n\nInstead of implementing a UI for sign-up and sign-in, this SDK provides the UI via a hosted page.  It supports sign-up, sign-in, confirmation, multifactor authentication, and sign-out.\n\n\n# Installation\n\nInstall amazon-cognito-auth-ts using yarn or npm:\n\n```\nyarn add amazon-cognito-auth-ts\n```\n\n\n### Install using separate JavaScript files\n\nTODO\n\n### Configuration\n\nThe Amazon Cognito Auth SDK for JavaScript requires three configuration values from your AWS Account in order to access your Cognito User Pool:\n\n* An User Pool App Client Id (required): e.g. `\u003cTODO: add ClientId\u003e` \n    * When creating the App, if the generate client secret box was **checked**, for /oauth2/token endpoint which gets the user's tokens, the client must pass its client_id and client_secret in the authorization header. For more info, please reference [here](http://docs.aws.amazon.com/cognito/latest/developerguide/token-endpoint.html).\n* An App Web Domain (required): e.g. `\u003cTODO: add App Web Domain\u003e`\n    * When you click the `Domain name` tab, you can create a domain name there and save it for record. \n* Scope Array (required): `['\u003cTODO: your scope array here, try \"phone\", \"email\", ...\u003e'],` e.g.`['phone', 'email', 'profile','openid', 'aws.cognito.signin.user.admin']` (to get more info about scope, please reference [\"scope\" section of our doc](http://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html))\n    * When you click the `App settings` tab, you can select the identity provider which you want to use on your App. \n    * In the `sign in and sign out URLs` tab, you can set the `Callback URLs` and `Sign out URLs`. (both are required)\n    * Under the `OAuth2.0` tab, you can select the OAuth flows and scopes enabled for this app. (both are required)\n* IdentityProvider (Optional): Pre-selected identity provider (this allows to automatically trigger social provider authentication flow).e.g. `Facebook`\n* UserPoolId (Optional): e.g. `\u003cTODO: add UserPoolId\u003e` \n* AdvancedSecurityDataCollectionFlag (Optional): boolean flag indicating if the data collection is enabled to support cognito advanced security features. By default, this flag is set to true.\n\nThe [AWS Console for Cognito User Pools](https://console.aws.amazon.com/cognito/users/) can be used to get or create these values.\n\nNote that the various errors returned by the service are valid JSON so one can access the different exception types (err.code) and status codes (err.statusCode).\n\n\n### Usage\n\nThe usage examples below use the unqualified names for types in the Amazon Cognito Auth SDK for JavaScript. Remember to import or qualify access to any of these types:\n\n```ts\nimport {CognitoAuth} from 'amazon-cognito-auth-ts';\n```\n\n**Use case 1.** Registering an auth with the application. You need to create a CognitoAuth object by providing a App client ID, a App web domain, a scope array, a sign-in redirect URL, and a sign-out redirect URL: (Identity Provider, UserPoolId and AdvancedSecurityDataCollectionFlag are optional values)\n\n```js\n/*\n  TokenScopesArray\n  Valid values are found under:\n  AWS Console -\u003e User Pools -\u003e \u003cYour user pool\u003e -\u003e App Integration -\u003e App client settings\n  Example values: ['profile', 'email', 'openid', 'aws.cognito.signin.user.admin', 'phone']\n\n  RedirectUriSignOut \n  This value must match the value specified under:\n  AWS Console -\u003e User Pools -\u003e \u003cYour user pool\u003e -\u003e App Integration -\u003e App client settings -\u003e Sign out URL(s)\n*/\nvar authData = {\n\tClientId : '\u003cTODO: add ClientId\u003e', // Your client id here\n\tAppWebDomain : '\u003cTODO: add App Web Domain\u003e',\n\tTokenScopesArray : ['\u003cTODO: add scope array\u003e'], // e.g.['phone', 'email', 'profile','openid', 'aws.cognito.signin.user.admin'],\n\tRedirectUriSignIn : '\u003cTODO: add redirect url when signed in\u003e',\n\tRedirectUriSignOut : '\u003cTODO: add redirect url when signed out\u003e',\n\tIdentityProvider : '\u003cTODO: add identity provider you want to specify\u003e', // e.g. 'Facebook',\n\tUserPoolId : '\u003cTODO: add UserPoolId\u003e', // Your user pool id here\n\tAdvancedSecurityDataCollectionFlag : '\u003cTODO: boolean value indicating whether you want to enable advanced security data collection\u003e', // e.g. true\n        Storage: '\u003cTODO the storage object\u003e' // OPTIONAL e.g. new CookieStorage(), to use the specified storage provided\n};\nvar auth = new CognitoAuth(authData);\n```\n\nAll the methods used in the authentication workflow are managed by \"promises\" unless you want to manage them through callback functions you need to set userhandler:\n\n```js\nauth.userhandler = {\n\tonSuccess: function(result) {\n\t\talert(\"Sign in success\");\n\t\tshowSignedIn(result);\n\t},\n\tonFailure: function(err) {\n\t\talert(\"Error!\");\n\t}\n};\n```\nYou can also set `state` parameter:\n\n```js\nauth.setState(\u003cstate parameter\u003e);\n```\n\n**Use case 2.** Sign-in using `getSession()` API:\n\n```js\nauth.getSession();\n```\n\nFor the cache tokens and scopes, use the `parseCognitoWebResponse(Response)` API, e.g. the response is the current window url:\n\n```js\nvar curUrl = window.location.href;\nauth.parseCognitoWebResponse(curUrl);\n```\nTypically, you can put this part of logic in the `onLoad()`, e.g.:\n\n```js\nfunction onLoad() {\n\tvar auth = initCognitoSDK();\n\tvar curUrl = window.location.href;\n\tauth.parseCognitoWebResponse(curUrl);\n}\n```\n\n**Use case 3.** Sign-out using `signOut()`:\n\n```js\nauth.signOut();\n```\n**Important to know**\n\nBy default, the SDK uses implicit flow(token flow), if you want to enable authorization code grant flow, you have two options:\n\nOption 1:\n```js\nvar auth = new CognitoAuth(authData, false);\n```\nOption 2:\n```js\nvar auth = new CognitoAuth(authData);\nauth.useCodeGrantFlow();. \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorrys%2Famazon-cognito-auth-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorrys%2Famazon-cognito-auth-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorrys%2Famazon-cognito-auth-ts/lists"}