Skip to content

Commit

Permalink
feat(chat): add cognito provider (Issue epam#1162) (epam#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kezik authored Mar 29, 2024
1 parent 4063487 commit 494091a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/chat/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ DIAL_API_VERSION="2023-03-15-preview"
# AUTH_PING_ID_SECRET=""
# AUTH_PING_ID_SCOPE=""

### Cognito
# AUTH_COGNITO_ID_CLIENT_ID=""
# AUTH_COGNITO_ID_HOST=""
# AUTH_COGNITO_ID_NAME=""
# AUTH_COGNITO_ID_SECRET=""
# AUTH_COGNITO_ID_SCOPE=""

# Overlay variables
# ALLOWED_IFRAME_ORIGINS=""
# IS_IFRAME="false"
Expand Down
5 changes: 5 additions & 0 deletions apps/chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,10 @@ Also we have a lot of auth specific env variables:
| `AUTH_PING_ID_NAME` | No | PingID Name | Any string | |
| `AUTH_PING_ID_SECRET` | No | PingID Secret | Any string | |
| `AUTH_PING_ID_SCOPE` | No | PingID Scope | Any string | `offline_access` |
| `AUTH_COGNITO_CLIENT_ID` | No | Cognito Client ID | Any string | |
| `AUTH_COGNITO_HOST` | No | Cognito Host | Any string | |
| `AUTH_COGNITO_NAME` | No | Cognito Name | Any string | |
| `AUTH_COGNITO_SECRET` | No | Cognito Secret | Any string | |
| `AUTH_COGNITO_SCOPE` | No | Cognito Scope | Any string | `openid email profile` |

_NOTE: to being able to test the app in unauthenticated mode just not set any of auth providers variables_
5 changes: 5 additions & 0 deletions apps/chat/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ declare global {
AUTH_PING_ID_NAME?: string;
AUTH_PING_ID_SECRET?: string;
AUTH_PING_ID_SCOPE?: string;
AUTH_COGNITO_CLIENT_ID?: string;
AUTH_COGNITO_SECRET?: string;
AUTH_COGNITO_HOST?: string;
AUTH_COGNITO_NAME?: string;
AUTH_COGNITO_SCOPE?: string;
}
}
}
17 changes: 17 additions & 0 deletions apps/chat/src/utils/auth/auth-providers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Provider } from 'next-auth/providers';
import Auth0Provider from 'next-auth/providers/auth0';
import AzureProvider from 'next-auth/providers/azure-ad';
import CognitoProvider from 'next-auth/providers/cognito';
import GoogleProvider from 'next-auth/providers/google';
import KeycloakProvider from 'next-auth/providers/keycloak';

Expand Down Expand Up @@ -119,6 +120,22 @@ const allProviders: (Provider | boolean)[] = [
},
token: tokenConfig,
}),

!!process.env.AUTH_COGNITO_CLIENT_ID &&
!!process.env.AUTH_COGNITO_SECRET &&
!!process.env.AUTH_COGNITO_HOST &&
CognitoProvider({
clientId: process.env.AUTH_COGNITO_CLIENT_ID,
clientSecret: process.env.AUTH_COGNITO_SECRET,
issuer: process.env.AUTH_COGNITO_HOST,
name: process.env.AUTH_COGNITO_NAME ?? DEFAULT_NAME,
authorization: {
params: {
scope: process.env.AUTH_COGNITO_SCOPE || 'openid email profile',
},
},
token: tokenConfig,
}),
];

export const authProviders = allProviders.filter(Boolean) as Provider[];
Expand Down

0 comments on commit 494091a

Please sign in to comment.