dcp3450
dcp3450

Reputation: 11187

aws-amplify Single login for multiple applications

I have multiple applications where the user logins via a cognito login. Currently they have to login at each application with the same cred. All apps live at the same domain. I need to allow the user to login to one location and when they attempt to access a new application verify their token. If valid, they've logged into another app, otherwise they haven't logged in yet.

tl;dr

They all have the same userpool and identity pool. I'm calling Auth.currentAuthenticatedUser(). From my understanding if they he same UP and IP ids and on the same domain it should allow access.

How do I authenticate at the second app without an actual login?

Platform: Angular 15

Libraries: @aws-amplify/ui-angular: 4 aws-amplify: 5

Upvotes: 1

Views: 751

Answers (2)

Peca021
Peca021

Reputation: 96

Also to make authentication more centralized and maintainable, you might consider extracting auth-related pages (login, register, forgot password, etc.) into a separate subdomain such as auth.yourdomain.com for example.

This way, the authentication logic acts as a single source of truth for all apps under the same domain, reducing duplication and improving security.

Many popular platforms use this approach to streamline authentication across multiple applications.

Upvotes: 0

Peca021
Peca021

Reputation: 96

I would say that if your apps are on the same domain you can use cookies to store and share authentication information across applications.

After a user is logged in, you can set cookies with user info (don't forget to use Secure attribute with your Domain and SameSite=None as an option. You can read more about how to work with cookies on the docs: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies)

After that, in your other apps, you will be able to read the data from the cookies and there will be everything that you need to treat your user as logged in.

Upvotes: 1

Related Questions