An auth provider for react-admin which handles authentication with AWS Cognito.
This repository contains:
ra-auth-cognito
packagera-auth-cognito
with your own UserPool.We need to add some minimal configuration to our UserPool instance to use it. This need to be done from the AWS Console.
admin
user and set their email. You may add the name
and picture
attribute as well for the react-admin identity feature.admin
group and assign the admin
user.user
and the user
role.App integration
section of your User Pool and click the Create app client
buttonsingle page
application with the following settings:
For the demo app, you need to setup environment variables. You can do this by creating a .env
file in the root of the project. The following variables are required:
VITE_COGNITO_USERPOOL_ID="userpool-id"
VITE_COGNITO_APP_CLIENT_ID="app-client-id"
make install start
to install the dependencies and start the Demo AppSetup the hosted UI for your user pool with the following options:
http://localhost:8081/auth-callback
http://localhost:8081/
Implicit grant
option.OpenId
, Email
, Profile
and aws.cognito.signin.user.admin
scopes are selected.To enable the hosted UI, you must also a domain in the App integration
section. Select a Cognito domain and copy its url.
Update the env file accordingly:
VITE_COGNITO_USERPOOL_ID="userpool-id"
VITE_COGNITO_APP_CLIENT_ID="app-client-id"
VITE_COGNITO_HOSTED_UI_URL="YOUR_URL"
Now that all is configured and running, you can browse to http://127.0.0.1:8081/ to access the React Admin App.
The first time you sign in with any of the users, you'll have to enter their temporary password and will be asked to enter a password of your choice.
user
will only grant the user
role permissionsadmin
will grant full admin
role permissions, allowing for instance to see the 'Users' resource in the main menuFeel free to play around with this demo, along with the Cognito config, to understand better how it works!
This repository and the code it contains are licensed under the MIT License and sponsored by marmelab.