How do I get a client ID and Client secret for a user in Cognito

0

I'm developing an API for a client for which their customers would call. I created a user pool and an API and set cognito as authorizer. I understand the endpoint the user can call to get the JWT, but there is nowhere in Cognito hver I can retrieve a client id and client secret for a given user.

What am I missing here?

3 Answers
0

Hello.

When using Amazon Cognito, the Client ID and Client Secret are associated with an App Client, not an individual user.

How you can get secrets:

Navigate to Cognito.

User Pools:

  • Choose the user pool you created.

App Clients:

  • Click on "App clients" on the left side menu.
  • Click on “Add an app client”.
  • Fill in the “App client name”.
  • Unselect "Generate client secret" if you are building a client-side application like a single-page app, because the client secret should not be stored in unsecure client-side code. For server-side applications, keep it selected.
  • Adjust other settings as per your use case and click “Create app client”.

Retrieve Client ID and Client Secret:

  • Go back to the “App clients” section.
  • You will see your new app client listed there. The “App client id” is visible directly on this page.
  • If you generated a client secret, click on “Show Details” to view the “App client secret”.

https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-client-apps.html

Regards, Andrii

profile picture
EXPERT
answered 7 months ago
  • I see - then I might be completly off track. What I need is to be able to create 100+ users that can authenticate and get access to my API's. Since the backend data is e.g order details for all those users, I need to be able to add a customerID field to each user so that I can respond with the user's own orders. One app Id per user doesn't seem like the right approach here :)

0

in AWS Cognito for your use case. AWS Cognito is designed to manage users and their attributes in a scalable way. Here’s how you might structure this:

  1. User Creation and Management Bulk User Creation:

Cognito doesn’t directly support bulk user creation. However, you can automate user creation using the AWS SDK (Boto3 for Python, etc.) by looping through your user data and making a call to create each user. API: admin_create_user(ClientId='your-app-client-id', Username='username', UserAttributes=[...]) User Attributes:

Add the customerID or any other custom attribute you need by modifying the user pool attributes. Navigate to "User Pools" → Your user pool → "Attributes" section → "Add custom attribute". When creating users (either through the AWS Management Console, AWS SDK, or AWS CLI), make sure to assign the relevant customerID.

  1. Authenticating Users Users authenticate through the Cognito User Pool. When users sign in, Cognito returns JWT tokens. Users pass these tokens in the Authorization header when making API requests.

Regards, Andrii

profile picture
EXPERT
answered 7 months ago
  • Thanks! Pt1 is fine, we can create them manually and assign id's Regarding pt2, since these users will only access the API I was looking for something else than basic auth with username and password.(i.e client id and client secret) that's not supported then?

0

If you're looking for an alternative to basic user authentication with username and password (like using API keys or client credentials for each user), AWS Cognito might not be the optimal solution since it primarily revolves around end-user authentication (with a username and password, or with tokens obtained via identity federation).

profile picture
EXPERT
answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions