@memberjunction/server 5.14.0 → 5.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.d.ts +0 -3
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +5 -7
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/initializeProviders.js +2 -2
- package/dist/auth/initializeProviders.js.map +1 -1
- package/dist/config.d.ts +37 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -0
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +3 -3
- package/dist/context.js.map +1 -1
- package/dist/generated/generated.d.ts +169 -0
- package/dist/generated/generated.d.ts.map +1 -1
- package/dist/generated/generated.js +909 -1
- package/dist/generated/generated.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/resolvers/DatasetResolver.d.ts +5 -0
- package/dist/resolvers/DatasetResolver.d.ts.map +1 -1
- package/dist/resolvers/DatasetResolver.js +35 -0
- package/dist/resolvers/DatasetResolver.js.map +1 -1
- package/package.json +60 -59
- package/src/__tests__/unifiedAuth.test.ts +3 -2
- package/src/auth/__tests__/backward-compatibility.test.ts +2 -3
- package/src/auth/index.ts +5 -8
- package/src/auth/initializeProviders.ts +2 -2
- package/src/config.ts +8 -0
- package/src/context.ts +3 -3
- package/src/generated/generated.ts +635 -2
- package/src/index.ts +21 -3
- package/src/resolvers/DatasetResolver.ts +36 -0
- package/dist/auth/AuthProviderFactory.d.ts +0 -68
- package/dist/auth/AuthProviderFactory.d.ts.map +0 -1
- package/dist/auth/AuthProviderFactory.js +0 -155
- package/dist/auth/AuthProviderFactory.js.map +0 -1
- package/dist/auth/BaseAuthProvider.d.ts +0 -41
- package/dist/auth/BaseAuthProvider.d.ts.map +0 -1
- package/dist/auth/BaseAuthProvider.js +0 -102
- package/dist/auth/BaseAuthProvider.js.map +0 -1
- package/dist/auth/IAuthProvider.d.ts +0 -46
- package/dist/auth/IAuthProvider.d.ts.map +0 -1
- package/dist/auth/IAuthProvider.js +0 -2
- package/dist/auth/IAuthProvider.js.map +0 -1
- package/dist/auth/providers/Auth0Provider.d.ts +0 -18
- package/dist/auth/providers/Auth0Provider.d.ts.map +0 -1
- package/dist/auth/providers/Auth0Provider.js +0 -52
- package/dist/auth/providers/Auth0Provider.js.map +0 -1
- package/dist/auth/providers/CognitoProvider.d.ts +0 -18
- package/dist/auth/providers/CognitoProvider.d.ts.map +0 -1
- package/dist/auth/providers/CognitoProvider.js +0 -56
- package/dist/auth/providers/CognitoProvider.js.map +0 -1
- package/dist/auth/providers/GoogleProvider.d.ts +0 -18
- package/dist/auth/providers/GoogleProvider.d.ts.map +0 -1
- package/dist/auth/providers/GoogleProvider.js +0 -51
- package/dist/auth/providers/GoogleProvider.js.map +0 -1
- package/dist/auth/providers/MSALProvider.d.ts +0 -18
- package/dist/auth/providers/MSALProvider.d.ts.map +0 -1
- package/dist/auth/providers/MSALProvider.js +0 -52
- package/dist/auth/providers/MSALProvider.js.map +0 -1
- package/dist/auth/providers/OktaProvider.d.ts +0 -18
- package/dist/auth/providers/OktaProvider.d.ts.map +0 -1
- package/dist/auth/providers/OktaProvider.js +0 -52
- package/dist/auth/providers/OktaProvider.js.map +0 -1
- package/dist/auth/tokenExpiredError.d.ts +0 -5
- package/dist/auth/tokenExpiredError.d.ts.map +0 -1
- package/dist/auth/tokenExpiredError.js +0 -12
- package/dist/auth/tokenExpiredError.js.map +0 -1
- package/src/auth/AuthProviderFactory.ts +0 -182
- package/src/auth/BaseAuthProvider.ts +0 -137
- package/src/auth/IAuthProvider.ts +0 -54
- package/src/auth/providers/Auth0Provider.ts +0 -45
- package/src/auth/providers/CognitoProvider.ts +0 -50
- package/src/auth/providers/GoogleProvider.ts +0 -45
- package/src/auth/providers/MSALProvider.ts +0 -45
- package/src/auth/providers/OktaProvider.ts +0 -46
- package/src/auth/tokenExpiredError.ts +0 -12
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { JwtHeader, JwtPayload, SigningKeyCallback } from 'jsonwebtoken';
|
|
2
|
-
import jwksClient from 'jwks-rsa';
|
|
3
|
-
import { AuthProviderConfig, AuthUserInfo } from '@memberjunction/core';
|
|
4
|
-
import { IAuthProvider } from './IAuthProvider.js';
|
|
5
|
-
import https from 'https';
|
|
6
|
-
import http from 'http';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Base implementation of IAuthProvider with common functionality
|
|
10
|
-
* Concrete providers should extend this class and use @RegisterClass decorator
|
|
11
|
-
* with BaseAuthProvider as the base class
|
|
12
|
-
*/
|
|
13
|
-
export abstract class BaseAuthProvider implements IAuthProvider {
|
|
14
|
-
name: string;
|
|
15
|
-
issuer: string;
|
|
16
|
-
audience: string;
|
|
17
|
-
jwksUri: string;
|
|
18
|
-
/** OAuth client ID for this provider (used by OAuth proxy for upstream auth) */
|
|
19
|
-
clientId?: string;
|
|
20
|
-
protected config: AuthProviderConfig;
|
|
21
|
-
protected jwksClient: jwksClient.JwksClient;
|
|
22
|
-
|
|
23
|
-
constructor(config: AuthProviderConfig) {
|
|
24
|
-
this.config = config;
|
|
25
|
-
this.name = config.name;
|
|
26
|
-
this.issuer = config.issuer;
|
|
27
|
-
this.audience = config.audience;
|
|
28
|
-
this.jwksUri = config.jwksUri;
|
|
29
|
-
this.clientId = config.clientId;
|
|
30
|
-
|
|
31
|
-
// Create HTTP agent with keep-alive to prevent socket hangups
|
|
32
|
-
const agent = this.jwksUri.startsWith('https')
|
|
33
|
-
? new https.Agent({
|
|
34
|
-
keepAlive: true,
|
|
35
|
-
keepAliveMsecs: 30000,
|
|
36
|
-
maxSockets: 50,
|
|
37
|
-
maxFreeSockets: 10,
|
|
38
|
-
timeout: 60000
|
|
39
|
-
})
|
|
40
|
-
: new http.Agent({
|
|
41
|
-
keepAlive: true,
|
|
42
|
-
keepAliveMsecs: 30000,
|
|
43
|
-
maxSockets: 50,
|
|
44
|
-
maxFreeSockets: 10,
|
|
45
|
-
timeout: 60000
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Initialize JWKS client with connection pooling and extended timeout
|
|
49
|
-
this.jwksClient = jwksClient({
|
|
50
|
-
jwksUri: this.jwksUri,
|
|
51
|
-
cache: true,
|
|
52
|
-
cacheMaxEntries: 5,
|
|
53
|
-
cacheMaxAge: 600000, // 10 minutes
|
|
54
|
-
timeout: 60000, // 60 seconds (increased from default 30s)
|
|
55
|
-
requestAgent: agent
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Validates that required configuration is present
|
|
61
|
-
*/
|
|
62
|
-
validateConfig(): boolean {
|
|
63
|
-
return !!(this.name && this.issuer && this.audience && this.jwksUri);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Gets the signing key for token verification with retry logic
|
|
68
|
-
*/
|
|
69
|
-
getSigningKey(header: JwtHeader, callback: SigningKeyCallback): void {
|
|
70
|
-
this.getSigningKeyWithRetry(header, 3, 1000)
|
|
71
|
-
.then((key) => {
|
|
72
|
-
const signingKey = 'publicKey' in key ? key.publicKey : key.rsaPublicKey;
|
|
73
|
-
callback(null, signingKey);
|
|
74
|
-
})
|
|
75
|
-
.catch((err) => {
|
|
76
|
-
console.error(`Error getting signing key for provider ${this.name} after retries:`, err);
|
|
77
|
-
callback(err);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Retrieves signing key with exponential backoff retry logic
|
|
83
|
-
*/
|
|
84
|
-
private async getSigningKeyWithRetry(
|
|
85
|
-
header: JwtHeader,
|
|
86
|
-
maxRetries: number,
|
|
87
|
-
initialDelayMs: number
|
|
88
|
-
): Promise<jwksClient.SigningKey> {
|
|
89
|
-
let lastError: Error | undefined;
|
|
90
|
-
|
|
91
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
92
|
-
try {
|
|
93
|
-
return await this.jwksClient.getSigningKey(header.kid);
|
|
94
|
-
} catch (err) {
|
|
95
|
-
lastError = err instanceof Error ? err : new Error(String(err));
|
|
96
|
-
|
|
97
|
-
// Check if this is a connection error that's worth retrying
|
|
98
|
-
const isRetryableError =
|
|
99
|
-
lastError.message.includes('socket hang up') ||
|
|
100
|
-
lastError.message.includes('ECONNRESET') ||
|
|
101
|
-
lastError.message.includes('ETIMEDOUT') ||
|
|
102
|
-
lastError.message.includes('ENOTFOUND') ||
|
|
103
|
-
lastError.message.includes('EAI_AGAIN');
|
|
104
|
-
|
|
105
|
-
if (!isRetryableError || attempt === maxRetries) {
|
|
106
|
-
throw lastError;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Exponential backoff: wait longer between each retry
|
|
110
|
-
const delayMs = initialDelayMs * Math.pow(2, attempt);
|
|
111
|
-
console.warn(
|
|
112
|
-
`Attempt ${attempt + 1}/${maxRetries + 1} failed for provider ${this.name}. ` +
|
|
113
|
-
`Retrying in ${delayMs}ms... Error: ${lastError.message}`
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
throw lastError || new Error('Failed to retrieve signing key');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Checks if a given issuer URL belongs to this provider
|
|
125
|
-
*/
|
|
126
|
-
matchesIssuer(issuer: string): boolean {
|
|
127
|
-
// Handle trailing slashes and case sensitivity
|
|
128
|
-
const normalizedIssuer = issuer.toLowerCase().replace(/\/$/, '');
|
|
129
|
-
const normalizedProviderIssuer = this.issuer.toLowerCase().replace(/\/$/, '');
|
|
130
|
-
return normalizedIssuer === normalizedProviderIssuer;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Abstract method for extracting user info - must be implemented by each provider
|
|
135
|
-
*/
|
|
136
|
-
abstract extractUserInfo(payload: JwtPayload): AuthUserInfo;
|
|
137
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { JwtHeader, JwtPayload, SigningKeyCallback } from 'jsonwebtoken';
|
|
2
|
-
import { AuthProviderConfig, AuthUserInfo } from '@memberjunction/core';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Interface for authentication providers in MemberJunction
|
|
6
|
-
* Enables support for any OAuth 2.0/OIDC compliant provider
|
|
7
|
-
*/
|
|
8
|
-
export interface IAuthProvider {
|
|
9
|
-
/**
|
|
10
|
-
* Unique name identifier for this provider
|
|
11
|
-
*/
|
|
12
|
-
name: string;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The issuer URL for this provider (must match the 'iss' claim in tokens)
|
|
16
|
-
*/
|
|
17
|
-
issuer: string;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* The expected audience for tokens from this provider
|
|
21
|
-
*/
|
|
22
|
-
audience: string;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The JWKS endpoint URL for retrieving signing keys
|
|
26
|
-
*/
|
|
27
|
-
jwksUri: string;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* OAuth client ID for this provider (optional, used by OAuth proxy for upstream authentication)
|
|
31
|
-
*/
|
|
32
|
-
clientId?: string;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Validates that the provider configuration is complete and valid
|
|
36
|
-
*/
|
|
37
|
-
validateConfig(): boolean;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Gets the signing key for token verification
|
|
41
|
-
*/
|
|
42
|
-
getSigningKey(header: JwtHeader, callback: SigningKeyCallback): void;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Extracts user information from the JWT payload
|
|
46
|
-
* Different providers use different claim names
|
|
47
|
-
*/
|
|
48
|
-
extractUserInfo(payload: JwtPayload): AuthUserInfo;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Checks if a given issuer URL belongs to this provider
|
|
52
|
-
*/
|
|
53
|
-
matchesIssuer(issuer: string): boolean;
|
|
54
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { JwtPayload } from 'jsonwebtoken';
|
|
2
|
-
import { RegisterClass } from '@memberjunction/global';
|
|
3
|
-
import { AuthProviderConfig, AuthUserInfo } from '@memberjunction/core';
|
|
4
|
-
import { BaseAuthProvider } from '../BaseAuthProvider.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Auth0 authentication provider implementation
|
|
8
|
-
*/
|
|
9
|
-
@RegisterClass(BaseAuthProvider, 'auth0')
|
|
10
|
-
export class Auth0Provider extends BaseAuthProvider {
|
|
11
|
-
constructor(config: AuthProviderConfig) {
|
|
12
|
-
super(config);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Extracts user information from Auth0 JWT payload
|
|
17
|
-
*/
|
|
18
|
-
extractUserInfo(payload: JwtPayload): AuthUserInfo {
|
|
19
|
-
// Auth0 uses standard OIDC claims
|
|
20
|
-
const email = payload.email as string | undefined;
|
|
21
|
-
const fullName = payload.name as string | undefined;
|
|
22
|
-
const firstName = payload.given_name as string | undefined;
|
|
23
|
-
const lastName = payload.family_name as string | undefined;
|
|
24
|
-
const preferredUsername = payload.preferred_username as string | undefined || email;
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
email,
|
|
28
|
-
firstName: firstName || fullName?.split(' ')[0],
|
|
29
|
-
lastName: lastName || fullName?.split(' ')[1] || fullName?.split(' ')[0],
|
|
30
|
-
fullName,
|
|
31
|
-
preferredUsername
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Validates Auth0-specific configuration
|
|
37
|
-
*/
|
|
38
|
-
validateConfig(): boolean {
|
|
39
|
-
const baseValid = super.validateConfig();
|
|
40
|
-
const hasClientId = !!this.config.clientId;
|
|
41
|
-
const hasDomain = !!this.config.domain;
|
|
42
|
-
|
|
43
|
-
return baseValid && hasClientId && hasDomain;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { JwtPayload } from 'jsonwebtoken';
|
|
2
|
-
import { RegisterClass } from '@memberjunction/global';
|
|
3
|
-
import { AuthProviderConfig, AuthUserInfo } from '@memberjunction/core';
|
|
4
|
-
import { BaseAuthProvider } from '../BaseAuthProvider.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* AWS Cognito authentication provider implementation
|
|
9
|
-
*/
|
|
10
|
-
@RegisterClass(BaseAuthProvider, 'cognito')
|
|
11
|
-
export class CognitoProvider extends BaseAuthProvider {
|
|
12
|
-
constructor(config: AuthProviderConfig) {
|
|
13
|
-
super(config);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Extracts user information from Cognito JWT payload
|
|
18
|
-
*/
|
|
19
|
-
extractUserInfo(payload: JwtPayload): AuthUserInfo {
|
|
20
|
-
// Cognito uses custom claims with 'cognito:' prefix for some fields
|
|
21
|
-
const email = payload.email as string | undefined ||
|
|
22
|
-
payload['cognito:username'] as string | undefined;
|
|
23
|
-
const fullName = payload.name as string | undefined;
|
|
24
|
-
const firstName = payload.given_name as string | undefined;
|
|
25
|
-
const lastName = payload.family_name as string | undefined;
|
|
26
|
-
const preferredUsername = payload['cognito:username'] as string | undefined ||
|
|
27
|
-
payload.preferred_username as string | undefined ||
|
|
28
|
-
email;
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
email,
|
|
32
|
-
firstName: firstName || fullName?.split(' ')[0],
|
|
33
|
-
lastName: lastName || fullName?.split(' ')[1] || fullName?.split(' ')[0],
|
|
34
|
-
fullName,
|
|
35
|
-
preferredUsername
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Validates Cognito-specific configuration
|
|
41
|
-
*/
|
|
42
|
-
validateConfig(): boolean {
|
|
43
|
-
const baseValid = super.validateConfig();
|
|
44
|
-
const hasClientId = !!this.config.clientId;
|
|
45
|
-
const hasRegion = !!this.config.region;
|
|
46
|
-
const hasUserPoolId = !!this.config.userPoolId;
|
|
47
|
-
|
|
48
|
-
return baseValid && hasClientId && hasRegion && hasUserPoolId;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { JwtPayload } from 'jsonwebtoken';
|
|
2
|
-
import { RegisterClass } from '@memberjunction/global';
|
|
3
|
-
import { AuthProviderConfig, AuthUserInfo } from '@memberjunction/core';
|
|
4
|
-
import { BaseAuthProvider } from '../BaseAuthProvider.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Google Identity Platform authentication provider implementation
|
|
9
|
-
*/
|
|
10
|
-
@RegisterClass(BaseAuthProvider, 'google')
|
|
11
|
-
export class GoogleProvider extends BaseAuthProvider {
|
|
12
|
-
constructor(config: AuthProviderConfig) {
|
|
13
|
-
super(config);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Extracts user information from Google JWT payload
|
|
18
|
-
*/
|
|
19
|
-
extractUserInfo(payload: JwtPayload): AuthUserInfo {
|
|
20
|
-
// Google uses standard OIDC claims
|
|
21
|
-
const email = payload.email as string | undefined;
|
|
22
|
-
const fullName = payload.name as string | undefined;
|
|
23
|
-
const firstName = payload.given_name as string | undefined;
|
|
24
|
-
const lastName = payload.family_name as string | undefined;
|
|
25
|
-
const preferredUsername = email; // Google typically uses email as username
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
email,
|
|
29
|
-
firstName: firstName || fullName?.split(' ')[0],
|
|
30
|
-
lastName: lastName || fullName?.split(' ')[1] || fullName?.split(' ')[0],
|
|
31
|
-
fullName,
|
|
32
|
-
preferredUsername
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Validates Google-specific configuration
|
|
38
|
-
*/
|
|
39
|
-
validateConfig(): boolean {
|
|
40
|
-
const baseValid = super.validateConfig();
|
|
41
|
-
const hasClientId = !!this.config.clientId;
|
|
42
|
-
|
|
43
|
-
return baseValid && hasClientId;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { JwtPayload } from 'jsonwebtoken';
|
|
2
|
-
import { RegisterClass } from '@memberjunction/global';
|
|
3
|
-
import { AuthProviderConfig, AuthUserInfo } from '@memberjunction/core';
|
|
4
|
-
import { BaseAuthProvider } from '../BaseAuthProvider.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Microsoft Authentication Library (MSAL) provider implementation
|
|
8
|
-
*/
|
|
9
|
-
@RegisterClass(BaseAuthProvider, 'msal')
|
|
10
|
-
export class MSALProvider extends BaseAuthProvider {
|
|
11
|
-
constructor(config: AuthProviderConfig) {
|
|
12
|
-
super(config);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Extracts user information from MSAL/Azure AD JWT payload
|
|
17
|
-
*/
|
|
18
|
-
extractUserInfo(payload: JwtPayload): AuthUserInfo {
|
|
19
|
-
// MSAL/Azure AD uses some custom claims
|
|
20
|
-
const email = payload.email as string | undefined || payload.preferred_username as string | undefined;
|
|
21
|
-
const fullName = payload.name as string | undefined;
|
|
22
|
-
const firstName = payload.given_name as string | undefined;
|
|
23
|
-
const lastName = payload.family_name as string | undefined;
|
|
24
|
-
const preferredUsername = payload.preferred_username as string | undefined;
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
email,
|
|
28
|
-
firstName: firstName || fullName?.split(' ')[0],
|
|
29
|
-
lastName: lastName || fullName?.split(' ')[1] || fullName?.split(' ')[0],
|
|
30
|
-
fullName,
|
|
31
|
-
preferredUsername
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Validates MSAL-specific configuration
|
|
37
|
-
*/
|
|
38
|
-
validateConfig(): boolean {
|
|
39
|
-
const baseValid = super.validateConfig();
|
|
40
|
-
const hasClientId = !!this.config.clientId;
|
|
41
|
-
const hasTenantId = !!this.config.tenantId;
|
|
42
|
-
|
|
43
|
-
return baseValid && hasClientId && hasTenantId;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { JwtPayload } from 'jsonwebtoken';
|
|
2
|
-
import { RegisterClass } from '@memberjunction/global';
|
|
3
|
-
import { AuthProviderConfig, AuthUserInfo } from '@memberjunction/core';
|
|
4
|
-
import { BaseAuthProvider } from '../BaseAuthProvider.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Okta authentication provider implementation
|
|
9
|
-
*/
|
|
10
|
-
@RegisterClass(BaseAuthProvider, 'okta')
|
|
11
|
-
export class OktaProvider extends BaseAuthProvider {
|
|
12
|
-
constructor(config: AuthProviderConfig) {
|
|
13
|
-
super(config);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Extracts user information from Okta JWT payload
|
|
18
|
-
*/
|
|
19
|
-
extractUserInfo(payload: JwtPayload): AuthUserInfo {
|
|
20
|
-
// Okta uses standard OIDC claims plus some custom ones
|
|
21
|
-
const email = payload.email as string | undefined || payload.preferred_username as string | undefined;
|
|
22
|
-
const fullName = payload.name as string | undefined;
|
|
23
|
-
const firstName = payload.given_name as string | undefined;
|
|
24
|
-
const lastName = payload.family_name as string | undefined;
|
|
25
|
-
const preferredUsername = payload.preferred_username as string | undefined || email;
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
email,
|
|
29
|
-
firstName: firstName || fullName?.split(' ')[0],
|
|
30
|
-
lastName: lastName || fullName?.split(' ')[1] || fullName?.split(' ')[0],
|
|
31
|
-
fullName,
|
|
32
|
-
preferredUsername
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Validates Okta-specific configuration
|
|
38
|
-
*/
|
|
39
|
-
validateConfig(): boolean {
|
|
40
|
-
const baseValid = super.validateConfig();
|
|
41
|
-
const hasClientId = !!this.config.clientId;
|
|
42
|
-
const hasDomain = !!this.config.domain;
|
|
43
|
-
|
|
44
|
-
return baseValid && hasClientId && hasDomain;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { GraphQLError } from 'graphql';
|
|
2
|
-
|
|
3
|
-
export class TokenExpiredError extends GraphQLError {
|
|
4
|
-
constructor(expiryDate: Date, message = 'The provided token has expired. Please authenticate again.') {
|
|
5
|
-
super(message, {
|
|
6
|
-
extensions: {
|
|
7
|
-
code: 'JWT_EXPIRED',
|
|
8
|
-
expiryDate: expiryDate.toISOString(),
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
}
|