In order for the auth system to function properly, there are some environment variables that are needed. Note that this information is also included in the /.env.example file.
In /.env, you will need to set the following variables:
# Change this to a secure string
JWT_SECRET=secret
# Set the expiration delay for the secure cookie with the JWT token
# Delay is in millisecond e.g. 7 days is 1000*60*60*24*7
SESSION_EXPIRY=1000 * 60 * 60 * 24 * 7
DOMAIN_SERVER=http://localhost:3080
DOMAIN_CLIENT=http://localhost:3080
Please Note: If you are wanting this to work in development mode, you will need to create a file called .env.development
in the root directory and set DOMAIN_CLIENT
to http://localhost:3090
or whatever port is provided by vite when runnning npm run frontend-dev
Important: When you run the app for the first time, you need to create a new account by clicking on "Sign up" on the login page. The first account you make will be the admin account. The admin account doesn't have any special features right now, but it might be useful if you want to make an admin dashboard to manage other users later.
To enable Google login, you must create an application in the Google Cloud Console and provide the client ID and client secret in the /.env
file.
- Go to "APIs and Services" in your Google Cloud account and click on "Credentials".
- Click on "Configure consent screen" and select "External" as the user type.
- Add "profile", "email" and "openid" as the scopes for your app. These are the first three checkboxes when you click on "Add or remove scopes".
- Click on "Save and continue" and then "Back to dashboard".
- Click on "Create Credentials" and then "OAuth client ID".
- Select "Web application" as the application type and give it a name.
- Add
http://yourdomain
,http://localhost:3080
andhttp://localhost:3090
to the authorized JavaScript origins. - Add
http://your-domain/oauth/google/callback
to the authorized redirect URIs. (if you use localhost then use thishttp://localhost:3080/oauth/google/callback
) - Click on "Create" and copy your client ID and client secret.
- Paste them into your
/.env
file. - Enable the feature in the
/.env
file
- Go to Facebook Developer Portal
- Create a new Application and give it a name
- In the Dashboard tab select product and select "Facebook login", then tap on "Configure" and "Settings". Male sure "OAuth client access", "Web OAuth access", "Apply HTTPS" and "Use limited mode for redirect URIs" are enabled
- In the Valid OAuth Redirect URIs add "your-domain/oauth/facebook/callback" (example: http://example.com/oauth/facebook/callback)
- Save changes and in the "settings" tab, reset the Client Secret
- Put the Client ID and Client Secret in the .env file:
FACEBOOK_CLIENT_ID=your_client_id
FACEBOOK_CLIENT_SECRET=your_client_secret
FACEBOOK_CALLBACK_URL=/oauth/facebook/callback # this should be the same for everyone
- Save the .env file
- Go to the Azure Portal and sign in with your account.
- In the search box, type "Azure Active Directory" and click on it.
- On the left menu, click on App registrations and then on New registration.
- Give your app a name and select Web as the platform type.
- In the Redirect URI field, enter
http://localhost:3080/oauth/openid/callback
and click on Register. - You will see an Overview page with some information about your app. Copy the Application (client) ID and the Directory (tenant) ID and save them somewhere.
- On the left menu, click on Authentication and check the boxes for Access tokens and ID tokens under Implicit grant and hybrid flows.
- On the left menu, click on Certificates & Secrets and then on New client secret. Give your secret a name and an expiration date and click on Add.
- You will see a Value column with your secret. Copy it and save it somewhere. Don't share it with anyone!
- Open the .env file in your project folder and add the following variables with the values you copied:
OPENID_CLIENT_ID=Your Application (client) ID
OPENID_CLIENT_SECRET=Your client secret
OPENID_ISSUER=https://login.microsoftonline.com/Your Directory (tenant ID)/v2.0/
OPENID_SESSION_SECRET=Any random string
OPENID_SCOPE=openid profile email #DO NOT CHANGE THIS
OPENID_CALLBACK_URL=/oauth/openid/callback # this should be the same for everyone
- Save the .env file and you're done! You have successfully set up OpenID authentication with Azure AD for your app.
- Create a new User Pool in Cognito:
- Ensure your Cognito user pool sign-in options include
User Name
andEmail
. - Ensure that
given_name
andfamily_name
are required attributes. - Add an initial app client:
- Set the app type to
Confidential client
- Select
Use Cognitio Hosted UI
and chose a domain name - Make sure
Generate a client secret
is set. - Set the
Allowed callback URLs
tohttps://YOUR_DOMAIN/oauth/openid/callback
- Under advanced settings make sure
Profile
is included in theOpenID Connect scopes
- Set the app type to
- Ensure your Cognito user pool sign-in options include
- Open your User Pool
- Go to the
App Integrations
tab - Open the app client we created above.
- Use the
User Pool ID
and your AWS region to construct the OPENID_ISSUER (see below) - Toggle
Show Client Secret
- Use the
Client ID
forOPENID_CLIENT_ID
- Use the
Client secret
forOPENID_CLIENT_SECRET
- Open the .env file in your project folder and add the following variables with the values you copied:
OPENID_CLIENT_ID=Your client ID
OPENID_CLIENT_SECRET=Your client secret
OPENID_ISSUER=https://cognito-idp.[AWS REGION].amazonaws.com/[USER POOL ID]/.well-known/openid-configuration
OPENID_SESSION_SECRET=Any random string
OPENID_SCOPE=openid profile email
OPENID_CALLBACK_URL=/oauth/openid/callback
- Save the .env file and you're done! You have successfully set up OpenID authentication with Cognito for your app.
- Go to your Github Developer settings
- Create a new Github app
- Give it a GitHub App name and set in the Homepage URL "your-domain") (example: http://localhost:3080)
- Add a callback URL and set it as "your-domain/oauth/github/callback" (example: http://localhost:3080/oauth/github/callback)
- Remove the Active checkbox in the Webhook section
- Save changes and generate a Client Secret
- In the Permissions & events tab select, open the Account Permissions and set Email addresses to Read-only
- Put the Client ID and Client Secret in the .env file:
GITHUB_CLIENT_ID=your_client_id
GITHUB_CLIENT_SECRET=your_client_secret
GITHUB_CALLBACK_URL=/oauth/github/callback # this should be the same for everyone
- Save the .env file
- Go to Discord Developer Portal
- Create a new Application and give it a name
- In the OAuth2 general settings add a redirect URL and set it as "your-domain/oauth/discord/callback" (example: http://localhost:3080/oauth/discord/callback)
- in the Default Authorization Link set applications.commands
- Save changes and reset the Client Secret
- Put the Client ID and Client Secret in the .env file:
DISCORD_CLIENT_ID=your_client_id
DISCORD_CLIENT_SECRET=your_client_secret
DISCORD_CALLBACK_URL=/oauth/discord/callback # this should be the same for everyone
- Save the .env file
in the .env file modify this 4 variables:
EMAIL_SERVICE= # eg. gmail
EMAIL_USERNAME= # eg. your email address if using gmail
EMAIL_PASSWORD= # eg. this is the "app password" if using gmail
EMAIL_FROM= # eg. email address for from field like [email protected]
EMAIL_SERVICE is the name of the email service you are using (Gmail, Outlook, Yahoo Mail, ProtonMail, iCloud Mail, etc.). EMAIL_USERNAME is the username of the email service (usually, it will be the email address, but in some cases, it can be an actual username used to access the account). EMAIL_PASSWORD is the password used to access the email service. This is not the password to access the email account directly, but a password specifically generated for this service. EMAIL_FROM is the email address that will appear in the "from" field when a user receives an email.
- Create a Google Account and enable 2-step verification.
- In the Google Account settings, click on the "Security" tab and open "2-step verification."
- Scroll down and open "App passwords." Choose "Mail" for the app and select "Other" for the device, then give it a random name.
- Click on "Generate" to create a password, and copy the generated password.
- In the .env file, modify the variables as follows:
EMAIL_SERVICE=gmail
EMAIL_USERNAME=your-email
EMAIL_PASSWORD=your-app-password
EMAIL_FROM=email address for the from field, e.g., [email protected]
NOTE: The variable EMAIL_FROM currently does not work. To stay updated, check the bug fixes here.
To disable or re-enable registration, open up the root .env
file and set ALLOW_REGISTRATION=true
or ALLOW_REGISTRATION=false
depending on if you want registration open or closed.
To disable or re-enable social registration, open up the root .env
file and set ALLOW_SOCIAL_REGISTRATION=true
or ALLOW_SOCIAL_REGISTRATION=false
depending on if you want social registration open or closed.
NOTE: OpenID does not support the ability to disable only registration.
If you previously implemented your own user system using the original scaffolding that was provided, you will no longer see conversations and presets by switching to the new user system. This is because of a design flaw in the scaffolding implementation that was problematic for the inclusion of social login.
When the first account is registered, the application will automatically migrate any conversations and presets that you created before the user system was implemented to that account. if you use login for the first time with a social login account (eg. Google, facebook, etc.), the conversations and presets that you created before the user system was implemented will NOT be migrated to that account.