Auth Keys in Wappi provide secure authentication token management for user sessions and API access. These keys are automatically rotated and managed by Wappi to ensure maximum security for your application.
Auth Keys are generated when users successfully authenticate through the Core_Login endpoint. These keys serve as session tokens that validate user identity and permissions for subsequent API requests.
1# Current and previous auth keys for rotation
2AUTH_KEY_CURRENT=your-current-auth-key-here
3AUTH_KEY_PREVIOUS=your-previous-auth-key-here
4
5# Environment setting affects key generation
6ENVIRONMENT=prod1{
2 "authRotation": "0 2 * * *", // Daily rotation at 2 AM
3 "apiKey": "your-api-key",
4 "domains": "yourdomain.com, app.yourdomain.com"
5}Auth Keys are automatically generated when users log in through your Core_Login endpoint:
1// API/Core/Login/1.0.0/index.ts
2export async function Core_Login_1_0_0(
3 body: Body,
4): Promise<Response> {
5 try {
6 if (!body) throw new Error('No Body')
7
8 // ⌄⌄⌄⌄⌄ ADD CUSTOM LOGIN LOGIC HERE ⌄⌄⌄⌄⌄
9
10 // ^^^^^ ADD CUSTOM LOGIN LOGIC HERE ^^^^^
11
12 return {}
13 // eslint-disable-next-line no-unreachable
14 } catch (err) {
15 console.error(err)
16 return {
17 error: err,
18 message: err.message,
19 devMessage: 'Fatal error in Core_Login_1_0_0. Investigate.',
20 success: false,
21 }
22 }
23}
24Wappi automatically rotates auth keys based on your configured schedule to enhance security:
1{
2 "authRotation": "*/30 * * * *", // Every 30 minutes (high security)
3 "authRotation": "0 */6 * * *", // Every 6 hours (balanced)
4 "authRotation": "0 0 * * *", // Daily (standard)
5 "authRotation": "0 0 * * 0", // Weekly (low security)
6 "authRotation": "0 0 1 * *", // Monthly (low security)
7 "authRotation": "0 0 1 */3 *", // Every 3 months (low security)
8 "authRotation": "0 0 1 */6 *", // Every 6 months (low security)
9 "authRotation": "0 0 1 1 *", // Yearly (Jan 1) (low security)
10}If you are using your API on a frontend application.
Auth Keys are automatically managed by wappi-fe.
Auth keys will be stored in a localStorage object
See Frontend Integration > Authentication
Wappi automatically validates auth keys on protected endpoints.
Every endpoint will pass through the auth data that your Core_Login_*** has returned.
This means that your auth key can contain any custom data you need for all endpoints.
For example. You have a API where a lot of endpoints require the validation of a "CompanyId". You can return this companyID in the auth token and it will be passed into every endpoint. Saving you an extra DB call.
Best practices: Don't pass through all user data in the auth key, it will make the auth key bloated. Just keep it simple and only include the fundamentals.
For production environments, rotate auth keys with AWS Secrets Manager.
In your wappiConfig.json file. If you're using AWS. You can add:
1"serverProvider": "AWS",If serverProvider is set to AWS. It will query your AWS secrets manager for your auth keys secret.
To customize your secret name and AWS region. Set the following Environment variables in your .env.example and .env files in production.
1AWS_AUTH_KEY_SECRET_NAME="authKeys" # Default === "authKeys"
2AWS_AUTH_KEY_SECRET_REGION="ap-southeast-2" # Default === "ap-southeast-2"If you are using this method, it's recommended that you rotate your AWS keys at the same rate as your auth rotation setting in your wappiConfig.json file.
Use a lambda to rotate your secrets.