Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito UI uses a hash to include parameters when it calls the callback page

I am having an issue with AWS Cognito provided UI.

When I am trying to use the provided UI, I call the endpoint with populated URL:

https://mydomain.auth.ap-northeast-1.amazoncognito.com/login?response_type=token&client_id=123456789&redirect_uri=http://localhost:3000/callback/

Now the problem is that, after authentication, Cognito uses a # to send back the required parameters. The result would look like this:

http://localhost:3000/callback/#id_token=eyJragIsm2PqVpw&access_token=eyJraWQiOiJ&expires_in=3600&token_type=Bearer

I have a hard time reading id_token and access_token in my callback page (which is a vue app).

How can I configure Cognito to use the usual question mark (?) to pass query string, Or, How can I read the passed parameters after hash (#).

I appreciate your advise on this.

like image 275
Arman Fatahi Avatar asked Aug 16 '18 14:08

Arman Fatahi


People also ask

How does AWS Cognito hash passwords?

Cognito Identity does not receive or store user credentials. Cognito Identity uses the token from the identity provider to obtain a unique identifier for the user and then hashes it using a one-way hash so that the same user can be recognized again in the future without storing the actual user identifier.

What is callback URL in AWS Cognito?

A callback URL is where the user is redirected to after a successful sign-in. Add a sign-out URL under Allowed sign-out URL(s). A sign-out URL is where your user is redirected to after signing out. Add at least one of the listed options from the list of Identity providers.

How do I customize my Cognito UI?

To specify app UI customization settingsSign in to the Amazon Cognito console . In the navigation pane, choose User Pools, and choose the user pool you want to edit. Choose the App integration tab. To customize UI settings for all app clients, locate Hosted UI customization and select Edit.

What functionality does Amazon Cognito provide?

Amazon Cognito provides authentication, authorization, and user management for your web and mobile apps. Your users can sign in directly with a user name and password, or through a third party such as Facebook, Amazon, Google or Apple. The two main components of Amazon Cognito are user pools and identity pools.


1 Answers

If you are using Vue.js router, it is actually pretty easy to process the hash part. Just put this snippet somewhere in your component. reference: https://router.vuejs.org/api/#the-route-object

let cognitoData = {}
if (this.$route.hash !== "") {
    let elementsString = decodeURIComponent(
        this.$route.hash.substr(1, this.$route.hash.length)
    );
    let params = elementsString.split("&");
    for (let param of params) {
        let values = param.split("=");
        cognitoData[values[0]] = values[1];
    }
}

// do your business with cognitoData
like image 115
FakeFootball Avatar answered Oct 07 '22 03:10

FakeFootball