AWS Cognito Authentication
Ⓔ Enterprise Only
This feature is available exclusively in Countly Enterprise.
Overview
The Cognito feature lets Countly authenticate users through Amazon Cognito instead of the default local authentication flow. It supports both:
- Authorization code login (Cognito redirects back to Countly with
code) - Header-based login (
X-Amzn-Oidc-Dataprovided by upstream auth infrastructure)
After identity data is validated, the feature maps Cognito groups to Countly roles and signs users into the dashboard.
API Surface
This feature does not expose standalone public endpoints under /i/cognito.
Instead, it extends Countly authentication routes:
<countlyPath>/login<countlyPath>/clogin/:code<countlyPath>/logout(GET and POST)
Key Features
- Cognito-based login for Countly users
- Authorization code flow with Cognito token exchange
- Header-based login using
X-Amzn-Oidc-Data - Group-to-role mapping against Countly groups
- Global admin elevation via a configured Cognito group
- Push approver permissions via configured Cognito groups
- Short-code bridge (
/clogin/:code) for completing authenticated sessions - Encrypted temporary auth payload storage before session creation
Authentication Workflows
1) Authorization Code Flow
User authenticates in Cognito
-> Cognito redirects to Countly login with ?code=...
-> Countly exchanges code at /oauth2/token
-> Countly fetches profile at /oauth2/userInfo
-> Countly reads groups from ID token claim "cognito:groups"
-> Countly stores encrypted short-code payload
-> User is redirected to /clogin/:code
-> Countly maps roles and creates/logs in member
2) Header Token Flow
Upstream auth sends X-Amzn-Oidc-Data header to Countly login
-> Countly decodes payload
-> Reads email + user identity + groups (custom:Role/custom:Groups)
-> Stores encrypted short-code payload
-> Redirects to /clogin/:code
-> Countly maps roles and creates/logs in member
3) Short-Code Completion Flow
<countlyPath>/clogin/:code:
- Reads encrypted payload from
shortCodecollection - Validates expiration (
urlExpireMinute) - Resolves Countly permissions from Cognito groups
- Creates/updates member via external auth flow
- Deletes used short code
- Redirects to dashboard
Configuration Settings
| Setting | Default | Required | Description | Environment Variable |
|---|---|---|---|---|
baseUrl | '' | Yes | Countly base URL; used for login redirect construction | COUNTLY_CONFIG_PLUGINCOGNITO_BASEURL |
cognitoHost | '' | Yes | Cognito host (for /oauth2/token, /oauth2/userInfo, /oauth2/revoke) | COUNTLY_CONFIG_PLUGINCOGNITO_COGNITOHOST |
cognitoClientId | '' | Yes | Cognito app client ID | COUNTLY_CONFIG_PLUGINCOGNITO_COGNITOCLIENTID |
cognitoClientSecret | '' | Yes | Cognito app client secret | COUNTLY_CONFIG_PLUGINCOGNITO_COGNITOCLIENTSECRET |
globalAdminGroup | 'countly-global-admin-group' | No | Cognito group that grants Countly global admin access | COUNTLY_CONFIG_PLUGINCOGNITO_GLOBALADMINGROUP |
pushApproverGroups | [''] | No | Cognito groups that grant push approver permissions | COUNTLY_CONFIG_PLUGINCOGNITO_PUSHAPPROVERGROUPS |
urlExpireMinute | 10 | No | Short-code payload expiration window (minutes) | COUNTLY_CONFIG_PLUGINCOGNITO_URLEXPIREMINUTE |
cognitoExternalLoginUrl | '' | No | Optional retry login URL shown on login error screen | COUNTLY_CONFIG_PLUGINCOGNITO_COGNITOEXTERNALLOGINURL |
Required Identity Data
| Field | Required | Source | Usage |
|---|---|---|---|
email | Yes | Cognito user info or token payload | Countly member email |
groups | Yes | cognito:groups (auth code flow) or custom:Role/custom:Groups (header flow) | Countly role mapping |
sub | No | Token payload | Used as member ID when available |
name | No | User info/token payload | Used as member full name |
username | No | User info/token payload | Used as member username |
If sub, name, or username are missing, the feature falls back to generated/derived values.
Group and Permission Mapping
Role resolution is based on Cognito group names:
- If user belongs to
globalAdminGroup, user becomes Countly global admin. - Otherwise, Cognito groups are matched against Countly groups by
nameorgroupID. - Mapped Countly group permissions are merged.
- If matched group is in
pushApproverGroups, push approver permissions are granted. - If no group matches, login is rejected.
Data Storage
| Collection | Purpose |
|---|---|
countly.members | Cognito-authenticated Countly users |
countly.groups | Source of Countly role definitions used during group mapping |
countly.shortCode | Temporary encrypted login payload keyed by short code |
Notes:
- Short-code expiration is checked using the stored
expiresvalue. - Used short codes are removed after successful login.
- The plugin does not create a TTL index for automatic short-code cleanup.
Configuration Methods
Method 1: config.js
Copy config.sample.js to config.js, then set values:
const config = {
baseUrl: "https://countly.company.com",
globalAdminGroup: "countly-global-admin-group",
urlExpireMinute: 10,
cognitoHost: "your-pool.auth.us-east-1.amazoncognito.com",
cognitoClientId: "your-client-id",
cognitoClientSecret: "your-client-secret",
pushApproverGroups: ["push-approver-group"],
cognitoExternalLoginUrl: ""
};
module.exports = require("../../api/configextender")("PLUGINCOGNITO", config, process.env, {
BASEURL: "baseUrl",
GLOBALADMINGROUP: "globalAdminGroup",
URLEXPIREMINUTE: "urlExpireMinute",
COGNITOHOST: "cognitoHost",
COGNITOCLIENTID: "cognitoClientId",
COGNITOCLIENTSECRET: "cognitoClientSecret",
PUSHAPPROVERGROUPS: "pushApproverGroups",
COGNITOEXTERNALLOGINURL: "cognitoExternalLoginUrl"
});
Method 2: Environment Variables
Set values with COUNTLY_CONFIG_PLUGINCOGNITO_ prefix:
export COUNTLY_CONFIG_PLUGINCOGNITO_BASEURL="https://countly.company.com"
export COUNTLY_CONFIG_PLUGINCOGNITO_COGNITOHOST="your-pool.auth.us-east-1.amazoncognito.com"
export COUNTLY_CONFIG_PLUGINCOGNITO_COGNITOCLIENTID="your-client-id"
export COUNTLY_CONFIG_PLUGINCOGNITO_COGNITOCLIENTSECRET="your-client-secret"
export COUNTLY_CONFIG_PLUGINCOGNITO_GLOBALADMINGROUP="countly-global-admin-group"
export COUNTLY_CONFIG_PLUGINCOGNITO_URLEXPIREMINUTE="10"
export COUNTLY_CONFIG_PLUGINCOGNITO_COGNITOEXTERNALLOGINURL=""
For pushApproverGroups, prefer configuring it in config.js to avoid formatting ambiguity.
AWS Cognito Setup
Step 1: Create Cognito User Pool
- Sign in to AWS Management Console.
- Open Amazon Cognito and create a User Pool.
- Configure sign-in options for your organization (email, username, etc.).
- Configure password policy and recovery options.
- Save the pool and note its region.
Step 2: Create and Configure App Client
- In your User Pool, open App integration.
- Create an app client for Countly.
- Enable authorization code flow.
- Configure callback URL as
<baseUrl>/login. - Save and record:
- App client ID
- App client secret
- User Pool domain host (used as
cognitoHost)
Step 3: Configure Group Strategy
- Create Cognito groups that represent your access model.
- Define one group for Countly global admin mapping (
globalAdminGroup). - Define optional groups for push approval (
pushApproverGroups). - Ensure users are assigned to expected groups.
Step 4: Configure Countly Plugin
- Set plugin config in
config.js(or environment variables). - Verify
baseUrl,cognitoHost,cognitoClientId, andcognitoClientSecret. - Verify group mapping settings (
globalAdminGroup,pushApproverGroups). - Set
urlExpireMinutebased on your login completion timeout preference.
Step 5: Enable Feature in Countly
- Open Management > Feature Management in Countly.
- Enable AWS Cognito.
- In multi-server environments, enable plugin state sync.
- Restart/reload services if required by your deployment process.
Setup Checklist
- Create Cognito app client and obtain host/client credentials.
- Set Cognito callback URL to
<baseUrl>/login. - Ensure user claims include email and group information.
- Configure plugin settings (
config.jsor environment variables). - Enable AWS Cognito in Countly Feature Management.
- In multi-server deployments, enable plugin-state sync.
Use Cases
Use Case 1: Standard Enterprise SSO
{
baseUrl: "https://analytics.company.com",
cognitoHost: "company-pool.auth.us-east-1.amazoncognito.com",
cognitoClientId: "client-id",
cognitoClientSecret: "client-secret",
globalAdminGroup: "analytics-admins",
pushApproverGroups: ["push-team"]
}
Result: Cognito users can sign in, and admin/push permissions are derived from mapped groups.
Use Case 2: Header-Based Login Behind Load Balancer/Auth Proxy
{
baseUrl: "https://analytics.company.com",
cognitoHost: "company-pool.auth.us-east-1.amazoncognito.com",
cognitoClientId: "client-id",
cognitoClientSecret: "client-secret",
urlExpireMinute: 10
}
Result: Upstream auth sends X-Amzn-Oidc-Data; Countly completes login via short-code flow.
Use Case 3: Short-Lived Login Completion Links
{
baseUrl: "https://analytics.company.com",
cognitoHost: "company-pool.auth.us-east-1.amazoncognito.com",
cognitoClientId: "client-id",
cognitoClientSecret: "client-secret",
urlExpireMinute: 3
}
Result: Unused short-code login payloads expire quickly, reducing replay window.
Troubleshooting
Missing Parameters
Symptom: redirected to login with missing parameter message.
Checks:
- Authorization code flow: ensure
codeexists in query. - Header flow: ensure
X-Amzn-Oidc-Datais present.
Missing Email or Groups
Symptom: redirected with missing email/groups message.
Checks:
- Ensure Cognito user profile provides email.
- Ensure group claims are present (
cognito:groupsor custom claims).
Login URL Expired
Symptom: redirected with "login url expired".
Checks:
- Increase
urlExpireMinuteif needed. - Reduce user delay between initial auth and
/clogin/:code.
User Cannot Access Expected Areas
Symptom: login succeeds but permissions are insufficient.
Checks:
- Verify Cognito group names match Countly group names or group IDs.
- Confirm
globalAdminGroupandpushApproverGroupsvalues. - Ensure target Countly groups exist and have correct permissions.
Logout Works Locally but Cognito Session Persists
Behavior:
- Plugin clears Countly session and attempts Cognito token revoke.
- Upstream SSO/session infrastructure may still require separate sign-out handling.
Additional Resources
Ⓔ Enterprise
This feature is part of Countly Enterprise.
Get Access:
Already a Customer? Use support portal if you have any questions.