amazon-archives / amazon-cognito-auth-js

The Amazon Cognito Auth SDK for JavaScript simplifies adding sign-up, sign-in with user profile functionality to web apps.
Apache License 2.0
423 stars 232 forks source link

Expected flow for getSession #128

Closed ebuychance closed 6 years ago

ebuychance commented 6 years ago

useCodeGrantFlow() enabled.

I hit the Cognito hosted UI login just fine and after authenticating but stepping through the code I hit the this.launchUri(URL) path of getSession().

This redirects me with a code and state param but no local storage is being set...

• Am I supposed to manually consume the code and set the local storage via the SDK methods? Or am I missing something?

• Is it safe to assume if I was granted a code and state that I successfully authenticated with the user pool?

I also notice the auth.userhandler callbacks are never hit which I do not understand. When trying to use the sample code example what should the auth redirects be set to so I can run it from the local file system?

A SDK flow diagram would help me understand how to use the Auth library properly, but any help would be greatly appreciated. Thanks.

       var authData = {
            ClientId: '2..................................k',
            AppWebDomain: 'xxxxx-dev2.auth.us-east-1.amazoncognito.com',
            TokenScopesArray: ['aws.cognito.signin.user.admin'], // ['openid','profile', email','phone']... more
            RedirectUriSignIn: 'http://localhost:9090/home',
            RedirectUriSignOut: 'http://localhost:9090/login',
            // IdentityProvider: '', 
            // UserPoolId: 'us-east-1_s.......a', 
            // AdvancedSecurityDataCollectionFlag: false
        };
craigatproperly commented 6 years ago

When the redirect comes back to your signing uri it will have parameters attached to the URI that carries the results of the login (localhost won't work, you have to register this URI with cognito, and it should be https to protect the parameters).

From the front page of the doc you process those parameters by calling: parseCognitoWebResponse

The section from the readme is:

For the cache tokens and scopes, use the parseCognitoWebResponse(Response) API, e.g. the response is the current window url:

var curUrl = window.location.href; auth.parseCognitoWebResponse(curUrl);