Skip to content

Commit 4ad11a4

Browse files
authored
feat: cognito oauth support custom domain
1 parent ceaa47b commit 4ad11a4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/runtime/server/lib/oauth/cognito.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export interface OAuthCognitoConfig {
4141
* @default process.env.NUXT_OAUTH_COGNITO_REDIRECT_URL or current URL
4242
*/
4343
redirectURL?: string
44+
/**
45+
* AWS Cognito App Custom Domain – some pool configurations require this
46+
* @default ''
47+
*/
48+
domain?: string
4449
}
4550

4651
export function oauthCognitoEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthCognitoConfig>) {
@@ -59,8 +64,10 @@ export function oauthCognitoEventHandler({ config, onSuccess, onError }: OAuthCo
5964
return onError(event, error)
6065
}
6166

62-
const authorizationURL = `https://${config.userPoolId}.auth.${config.region}.amazoncognito.com/oauth2/authorize`
63-
const tokenURL = `https://${config.userPoolId}.auth.${config.region}.amazoncognito.com/oauth2/token`
67+
const urlBase = config?.domain || `${config.userPoolId}.auth.${config.region}.amazoncognito.com`
68+
69+
const authorizationURL = `https://${urlBase}/oauth2/authorize`
70+
const tokenURL = `https://${urlBase}/oauth2/token`
6471

6572
const redirectURL = config.redirectURL || getRequestURL(event).href
6673
if (!code) {
@@ -107,7 +114,7 @@ export function oauthCognitoEventHandler({ config, onSuccess, onError }: OAuthCo
107114
const accessToken = tokens.access_token
108115
// TODO: improve typing
109116
// eslint-disable-next-line @typescript-eslint/no-explicit-any
110-
const user: any = await $fetch(`https://${config.userPoolId}.auth.${config.region}.amazoncognito.com/oauth2/userInfo`, {
117+
const user: any = await $fetch(`https://${urlBase}/oauth2/userInfo`, {
111118
headers: {
112119
Authorization: `${tokenType} ${accessToken}`,
113120
},

0 commit comments

Comments
 (0)