0

I have been asked to do a coding challenge and to build a mini app which uses AWS Cognito for authentication.

I have been giving the following keys:

UserPoolId: "us-east-1_dJfLT4QIp"
ClientId: "194t5jewd8o56ppmbjjlvdt6yi"

(not the real details).

I can comfortably follow this tutorial: https://medium.com/better-programming/create-a-fully-functioning-user-authentication-with-aws-cognito-and-amplify-with-angular-complete-a3ce58df1b74

Which goes from having no AWS account to using AWS Cognito for login, however I don't understand how to integrate the keys I've been provided with into my application.

Is it possible to set these keys somewhere in my application to access a preexisting UserPool?

This is currently the most promising path I have: https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-integrating-user-pools-with-identity-pools.html

JoshuaESummers
  • 493
  • 2
  • 7
  • 24

1 Answers1

1

Joshua in the demo I had on medium I just hard coded the parameters in. But you could also put them in your environment file in Angular and then map them to the user pool object you are initializing the SDK with. Here's a link to an article on the environment files.

import {CognitoUserPool} from 'amazon-cognito-identity-js';
const PC = {
    UserPoolId: 'Your user pool id',
    ClientId: 'Your Client ID'
};
const userPool = new CognitoUserPool(PC);

So if you have the parameters in your environment then you would import that:

import { environment } from '../environments/environment';


And you would configure the userpoolID in the environment file:

export const environment = { UserPoolId: 'Your user pool id', ClientId: 'Your Client ID' };


If these are the only keys you can pass the entire imported environment to the SDK:

    const userPool = new CognitoUserPool(environment);


I also wrote an article on how to setup Cognito using AWS Amplify and Google federated identities, so you can have a look at that an see how the amplify exports are imported:

https://medium.com/@ole.ersoy/adding-aws-cognito-federated-login-with-google-using-aws-amplify-78bf68f19c68


Ole
  • 41,793
  • 59
  • 191
  • 359
  • Hi @Ole, thank you very much for getting back to me. I will give it a go now and let you know. – JoshuaESummers Feb 06 '20 at 14:52
  • import {CognitoUserPool} from 'amazon-cognito-identity-js'; - which file do you put this in?, the user-authentification.component.ts (and the dashboard?) or somewhere different all together – JoshuaESummers Feb 06 '20 at 17:31
  • I also was able to follow your medium demo without hardcoding any parameters in, so I don't know where you did that... – JoshuaESummers Feb 06 '20 at 17:59
  • I have also written this question now: https://stackoverflow.com/questions/60101611/where-to-create-aws-cognitouserpool-in-an-angular-8-application – JoshuaESummers Feb 06 '20 at 18:44
  • Take a look at this: https://aws-amplify.github.io/docs/js/api#manual-configuration – Ole Feb 17 '20 at 20:04
  • And this: https://aws-amplify.github.io/docs/js/api#manual-setup – Ole Feb 17 '20 at 20:38