@memberjunction/auth-providers 0.0.1 → 5.17.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/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +18 -0
- package/dist/AuthProviderFactory.d.ts +68 -0
- package/dist/AuthProviderFactory.d.ts.map +1 -0
- package/dist/AuthProviderFactory.js +153 -0
- package/dist/AuthProviderFactory.js.map +1 -0
- package/dist/BaseAuthProvider.d.ts +41 -0
- package/dist/BaseAuthProvider.d.ts.map +1 -0
- package/dist/BaseAuthProvider.js +102 -0
- package/dist/BaseAuthProvider.js.map +1 -0
- package/dist/IAuthProvider.d.ts +46 -0
- package/dist/IAuthProvider.d.ts.map +1 -0
- package/dist/IAuthProvider.js +2 -0
- package/dist/IAuthProvider.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/Auth0Provider.d.ts +18 -0
- package/dist/providers/Auth0Provider.d.ts.map +1 -0
- package/dist/providers/Auth0Provider.js +52 -0
- package/dist/providers/Auth0Provider.js.map +1 -0
- package/dist/providers/CognitoProvider.d.ts +18 -0
- package/dist/providers/CognitoProvider.d.ts.map +1 -0
- package/dist/providers/CognitoProvider.js +56 -0
- package/dist/providers/CognitoProvider.js.map +1 -0
- package/dist/providers/GoogleProvider.d.ts +18 -0
- package/dist/providers/GoogleProvider.d.ts.map +1 -0
- package/dist/providers/GoogleProvider.js +51 -0
- package/dist/providers/GoogleProvider.js.map +1 -0
- package/dist/providers/MSALProvider.d.ts +18 -0
- package/dist/providers/MSALProvider.d.ts.map +1 -0
- package/dist/providers/MSALProvider.js +52 -0
- package/dist/providers/MSALProvider.js.map +1 -0
- package/dist/providers/OktaProvider.d.ts +18 -0
- package/dist/providers/OktaProvider.d.ts.map +1 -0
- package/dist/providers/OktaProvider.js +52 -0
- package/dist/providers/OktaProvider.js.map +1 -0
- package/dist/tokenExpiredError.d.ts +5 -0
- package/dist/tokenExpiredError.d.ts.map +1 -0
- package/dist/tokenExpiredError.js +12 -0
- package/dist/tokenExpiredError.js.map +1 -0
- package/package.json +28 -7
- package/src/AuthProviderFactory.ts +180 -0
- package/src/BaseAuthProvider.ts +137 -0
- package/src/IAuthProvider.ts +54 -0
- package/src/index.ts +7 -0
- package/src/providers/Auth0Provider.ts +45 -0
- package/src/providers/CognitoProvider.ts +50 -0
- package/src/providers/GoogleProvider.ts +45 -0
- package/src/providers/MSALProvider.ts +45 -0
- package/src/providers/OktaProvider.ts +46 -0
- package/src/tokenExpiredError.ts +12 -0
- package/tsconfig.json +10 -0
- package/vitest.config.ts +11 -0
- package/README.md +0 -45
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @memberjunction/auth-providers
|
|
2
|
+
|
|
3
|
+
## 5.17.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [9881045]
|
|
8
|
+
- @memberjunction/core@5.17.0
|
|
9
|
+
- @memberjunction/global@5.17.0
|
|
10
|
+
|
|
11
|
+
## 5.16.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [2387400]
|
|
16
|
+
- Updated dependencies [11dba07]
|
|
17
|
+
- @memberjunction/core@5.16.0
|
|
18
|
+
- @memberjunction/global@5.16.0
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AuthProviderConfig } from '@memberjunction/core';
|
|
2
|
+
import { IAuthProvider } from './IAuthProvider.js';
|
|
3
|
+
import { BaseSingleton } from '@memberjunction/global';
|
|
4
|
+
import './providers/Auth0Provider.js';
|
|
5
|
+
import './providers/MSALProvider.js';
|
|
6
|
+
import './providers/OktaProvider.js';
|
|
7
|
+
import './providers/CognitoProvider.js';
|
|
8
|
+
import './providers/GoogleProvider.js';
|
|
9
|
+
/**
|
|
10
|
+
* Factory and registry for managing authentication providers
|
|
11
|
+
* Combines provider creation and lifecycle management in a single class
|
|
12
|
+
*/
|
|
13
|
+
export declare class AuthProviderFactory extends BaseSingleton<AuthProviderFactory> {
|
|
14
|
+
private providers;
|
|
15
|
+
private issuerCache;
|
|
16
|
+
private issuerMultiCache;
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Gets the singleton instance of the factory
|
|
20
|
+
*/
|
|
21
|
+
static get Instance(): AuthProviderFactory;
|
|
22
|
+
/**
|
|
23
|
+
* Creates an authentication provider instance based on configuration
|
|
24
|
+
* Uses MJGlobal ClassFactory to instantiate the correct provider class
|
|
25
|
+
*/
|
|
26
|
+
static createProvider(config: AuthProviderConfig): IAuthProvider;
|
|
27
|
+
/**
|
|
28
|
+
* Registers a new authentication provider
|
|
29
|
+
*/
|
|
30
|
+
register(provider: IAuthProvider): void;
|
|
31
|
+
/**
|
|
32
|
+
* Gets a provider by its issuer URL
|
|
33
|
+
*/
|
|
34
|
+
getByIssuer(issuer: string): IAuthProvider | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Gets all providers matching an issuer URL.
|
|
37
|
+
* Unlike getByIssuer() which returns only the first match, this returns
|
|
38
|
+
* all providers for a given issuer. This is needed when multiple apps
|
|
39
|
+
* (e.g. MJExplorer + MJCentral) share the same Auth0 domain but have
|
|
40
|
+
* different audiences (client IDs).
|
|
41
|
+
*/
|
|
42
|
+
getAllByIssuer(issuer: string): IAuthProvider[];
|
|
43
|
+
/**
|
|
44
|
+
* Gets a provider by its name
|
|
45
|
+
*/
|
|
46
|
+
getByName(name: string): IAuthProvider | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Gets all registered providers
|
|
49
|
+
*/
|
|
50
|
+
getAllProviders(): IAuthProvider[];
|
|
51
|
+
/**
|
|
52
|
+
* Checks if any providers are registered
|
|
53
|
+
*/
|
|
54
|
+
hasProviders(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Clears all registered providers (useful for testing)
|
|
57
|
+
*/
|
|
58
|
+
clear(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Gets all registered provider types from the ClassFactory
|
|
61
|
+
*/
|
|
62
|
+
static getRegisteredProviderTypes(): string[];
|
|
63
|
+
/**
|
|
64
|
+
* Checks if a provider type is registered
|
|
65
|
+
*/
|
|
66
|
+
static isProviderTypeRegistered(type: string): boolean;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=AuthProviderFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthProviderFactory.d.ts","sourceRoot":"","sources":["../src/AuthProviderFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAY,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,8BAA8B,CAAC;AACtC,OAAO,6BAA6B,CAAC;AACrC,OAAO,6BAA6B,CAAC;AACrC,OAAO,gCAAgC,CAAC;AACxC,OAAO,+BAA+B,CAAC;AAEvC;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,aAAa,CAAC,mBAAmB,CAAC;IACzE,OAAO,CAAC,SAAS,CAAyC;IAC1D,OAAO,CAAC,WAAW,CAAyC;IAC5D,OAAO,CAAC,gBAAgB,CAA2C;;IAMnE;;OAEG;IACH,WAAkB,QAAQ,IAAI,mBAAmB,CAEhD;IAED;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,aAAa;IAsBhE;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;IAcvC;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAkBtD;;;;;;OAMG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE;IAoB/C;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAIlD;;OAEG;IACH,eAAe,IAAI,aAAa,EAAE;IAIlC;;OAEG;IACH,YAAY,IAAI,OAAO;IAIvB;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,MAAM,CAAC,0BAA0B,IAAI,MAAM,EAAE;IAW7C;;OAEG;IACH,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CASvD"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { BaseAuthProvider } from './BaseAuthProvider.js';
|
|
2
|
+
import { MJGlobal, BaseSingleton } from '@memberjunction/global';
|
|
3
|
+
// Import providers to ensure they're registered
|
|
4
|
+
import './providers/Auth0Provider.js';
|
|
5
|
+
import './providers/MSALProvider.js';
|
|
6
|
+
import './providers/OktaProvider.js';
|
|
7
|
+
import './providers/CognitoProvider.js';
|
|
8
|
+
import './providers/GoogleProvider.js';
|
|
9
|
+
/**
|
|
10
|
+
* Factory and registry for managing authentication providers
|
|
11
|
+
* Combines provider creation and lifecycle management in a single class
|
|
12
|
+
*/
|
|
13
|
+
export class AuthProviderFactory extends BaseSingleton {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.providers = new Map();
|
|
17
|
+
this.issuerCache = new Map();
|
|
18
|
+
this.issuerMultiCache = new Map();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets the singleton instance of the factory
|
|
22
|
+
*/
|
|
23
|
+
static get Instance() {
|
|
24
|
+
return AuthProviderFactory.getInstance();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates an authentication provider instance based on configuration
|
|
28
|
+
* Uses MJGlobal ClassFactory to instantiate the correct provider class
|
|
29
|
+
*/
|
|
30
|
+
static createProvider(config) {
|
|
31
|
+
try {
|
|
32
|
+
// Use MJGlobal ClassFactory to create the provider instance
|
|
33
|
+
// The provider type in config should match the key used in @RegisterClass
|
|
34
|
+
// The config is passed as a constructor parameter via the spread operator
|
|
35
|
+
const provider = MJGlobal.Instance.ClassFactory.CreateInstance(BaseAuthProvider, config.type.toLowerCase(), config);
|
|
36
|
+
if (!provider) {
|
|
37
|
+
throw new Error(`No provider registered for type: ${config.type}`);
|
|
38
|
+
}
|
|
39
|
+
return provider;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
43
|
+
throw new Error(`Failed to create authentication provider for type '${config.type}': ${message}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Registers a new authentication provider
|
|
48
|
+
*/
|
|
49
|
+
register(provider) {
|
|
50
|
+
if (!provider.validateConfig()) {
|
|
51
|
+
throw new Error(`Invalid configuration for provider: ${provider.name}`);
|
|
52
|
+
}
|
|
53
|
+
this.providers.set(provider.name, provider);
|
|
54
|
+
// Clear issuer caches when registering new provider
|
|
55
|
+
this.issuerCache.clear();
|
|
56
|
+
this.issuerMultiCache.clear();
|
|
57
|
+
console.log(`Registered auth provider: ${provider.name} with issuer: ${provider.issuer}`);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gets a provider by its issuer URL
|
|
61
|
+
*/
|
|
62
|
+
getByIssuer(issuer) {
|
|
63
|
+
// Check cache first
|
|
64
|
+
if (this.issuerCache.has(issuer)) {
|
|
65
|
+
return this.issuerCache.get(issuer);
|
|
66
|
+
}
|
|
67
|
+
// Search through providers
|
|
68
|
+
for (const provider of this.providers.values()) {
|
|
69
|
+
if (provider.matchesIssuer(issuer)) {
|
|
70
|
+
// Cache for future lookups
|
|
71
|
+
this.issuerCache.set(issuer, provider);
|
|
72
|
+
return provider;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Gets all providers matching an issuer URL.
|
|
79
|
+
* Unlike getByIssuer() which returns only the first match, this returns
|
|
80
|
+
* all providers for a given issuer. This is needed when multiple apps
|
|
81
|
+
* (e.g. MJExplorer + MJCentral) share the same Auth0 domain but have
|
|
82
|
+
* different audiences (client IDs).
|
|
83
|
+
*/
|
|
84
|
+
getAllByIssuer(issuer) {
|
|
85
|
+
// Check multi-provider cache first
|
|
86
|
+
if (this.issuerMultiCache.has(issuer)) {
|
|
87
|
+
return this.issuerMultiCache.get(issuer);
|
|
88
|
+
}
|
|
89
|
+
const matches = [];
|
|
90
|
+
for (const provider of this.providers.values()) {
|
|
91
|
+
if (provider.matchesIssuer(issuer)) {
|
|
92
|
+
matches.push(provider);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (matches.length > 0) {
|
|
96
|
+
this.issuerMultiCache.set(issuer, matches);
|
|
97
|
+
}
|
|
98
|
+
return matches;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets a provider by its name
|
|
102
|
+
*/
|
|
103
|
+
getByName(name) {
|
|
104
|
+
return this.providers.get(name);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Gets all registered providers
|
|
108
|
+
*/
|
|
109
|
+
getAllProviders() {
|
|
110
|
+
return Array.from(this.providers.values());
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Checks if any providers are registered
|
|
114
|
+
*/
|
|
115
|
+
hasProviders() {
|
|
116
|
+
return this.providers.size > 0;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Clears all registered providers (useful for testing)
|
|
120
|
+
*/
|
|
121
|
+
clear() {
|
|
122
|
+
this.providers.clear();
|
|
123
|
+
this.issuerCache.clear();
|
|
124
|
+
this.issuerMultiCache.clear();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Gets all registered provider types from the ClassFactory
|
|
128
|
+
*/
|
|
129
|
+
static getRegisteredProviderTypes() {
|
|
130
|
+
// Get all registrations for BaseAuthProvider from ClassFactory
|
|
131
|
+
const registrations = MJGlobal.Instance.ClassFactory.GetAllRegistrations(BaseAuthProvider);
|
|
132
|
+
// Extract unique keys (provider types) from registrations
|
|
133
|
+
const providerTypes = registrations
|
|
134
|
+
.map(reg => reg.Key)
|
|
135
|
+
.filter((key) => key !== null && key !== undefined);
|
|
136
|
+
// Return unique provider types
|
|
137
|
+
return Array.from(new Set(providerTypes));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Checks if a provider type is registered
|
|
141
|
+
*/
|
|
142
|
+
static isProviderTypeRegistered(type) {
|
|
143
|
+
try {
|
|
144
|
+
// Try to get the registration for this specific type
|
|
145
|
+
const registration = MJGlobal.Instance.ClassFactory.GetRegistration(BaseAuthProvider, type.toLowerCase());
|
|
146
|
+
return registration !== null && registration !== undefined;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=AuthProviderFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthProviderFactory.js","sourceRoot":"","sources":["../src/AuthProviderFactory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEjE,gDAAgD;AAChD,OAAO,8BAA8B,CAAC;AACtC,OAAO,6BAA6B,CAAC;AACrC,OAAO,6BAA6B,CAAC;AACrC,OAAO,gCAAgC,CAAC;AACxC,OAAO,+BAA+B,CAAC;AAEvC;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,aAAkC;IAKzE;QACE,KAAK,EAAE,CAAC;QALF,cAAS,GAA+B,IAAI,GAAG,EAAE,CAAC;QAClD,gBAAW,GAA+B,IAAI,GAAG,EAAE,CAAC;QACpD,qBAAgB,GAAiC,IAAI,GAAG,EAAE,CAAC;IAInE,CAAC;IAED;;OAEG;IACI,MAAM,KAAK,QAA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M,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Base implementation of IAuthProvider with common functionality
|
|
7
|
+
* Concrete providers should extend this class and use @RegisterClass decorator
|
|
8
|
+
* with BaseAuthProvider as the base class
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class BaseAuthProvider implements IAuthProvider {
|
|
11
|
+
name: string;
|
|
12
|
+
issuer: string;
|
|
13
|
+
audience: string;
|
|
14
|
+
jwksUri: string;
|
|
15
|
+
/** OAuth client ID for this provider (used by OAuth proxy for upstream auth) */
|
|
16
|
+
clientId?: string;
|
|
17
|
+
protected config: AuthProviderConfig;
|
|
18
|
+
protected jwksClient: jwksClient.JwksClient;
|
|
19
|
+
constructor(config: AuthProviderConfig);
|
|
20
|
+
/**
|
|
21
|
+
* Validates that required configuration is present
|
|
22
|
+
*/
|
|
23
|
+
validateConfig(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Gets the signing key for token verification with retry logic
|
|
26
|
+
*/
|
|
27
|
+
getSigningKey(header: JwtHeader, callback: SigningKeyCallback): void;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves signing key with exponential backoff retry logic
|
|
30
|
+
*/
|
|
31
|
+
private getSigningKeyWithRetry;
|
|
32
|
+
/**
|
|
33
|
+
* Checks if a given issuer URL belongs to this provider
|
|
34
|
+
*/
|
|
35
|
+
matchesIssuer(issuer: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Abstract method for extracting user info - must be implemented by each provider
|
|
38
|
+
*/
|
|
39
|
+
abstract extractUserInfo(payload: JwtPayload): AuthUserInfo;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=BaseAuthProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseAuthProvider.d.ts","sourceRoot":"","sources":["../src/BaseAuthProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,UAAU,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAInD;;;;GAIG;AACH,8BAAsB,gBAAiB,YAAW,aAAa;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,MAAM,EAAE,kBAAkB,CAAC;IACrC,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC;gBAEhC,MAAM,EAAE,kBAAkB;IAoCtC;;OAEG;IACH,cAAc,IAAI,OAAO;IAIzB;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAYpE;;OAEG;YACW,sBAAsB;IAuCpC;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAOtC;;OAEG;IACH,QAAQ,CAAC,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,YAAY;CAC5D"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import jwksClient from 'jwks-rsa';
|
|
2
|
+
import https from 'https';
|
|
3
|
+
import http from 'http';
|
|
4
|
+
/**
|
|
5
|
+
* Base implementation of IAuthProvider with common functionality
|
|
6
|
+
* Concrete providers should extend this class and use @RegisterClass decorator
|
|
7
|
+
* with BaseAuthProvider as the base class
|
|
8
|
+
*/
|
|
9
|
+
export class BaseAuthProvider {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.name = config.name;
|
|
13
|
+
this.issuer = config.issuer;
|
|
14
|
+
this.audience = config.audience;
|
|
15
|
+
this.jwksUri = config.jwksUri;
|
|
16
|
+
this.clientId = config.clientId;
|
|
17
|
+
// Create HTTP agent with keep-alive to prevent socket hangups
|
|
18
|
+
const agent = this.jwksUri.startsWith('https')
|
|
19
|
+
? new https.Agent({
|
|
20
|
+
keepAlive: true,
|
|
21
|
+
keepAliveMsecs: 30000,
|
|
22
|
+
maxSockets: 50,
|
|
23
|
+
maxFreeSockets: 10,
|
|
24
|
+
timeout: 60000
|
|
25
|
+
})
|
|
26
|
+
: new http.Agent({
|
|
27
|
+
keepAlive: true,
|
|
28
|
+
keepAliveMsecs: 30000,
|
|
29
|
+
maxSockets: 50,
|
|
30
|
+
maxFreeSockets: 10,
|
|
31
|
+
timeout: 60000
|
|
32
|
+
});
|
|
33
|
+
// Initialize JWKS client with connection pooling and extended timeout
|
|
34
|
+
this.jwksClient = jwksClient({
|
|
35
|
+
jwksUri: this.jwksUri,
|
|
36
|
+
cache: true,
|
|
37
|
+
cacheMaxEntries: 5,
|
|
38
|
+
cacheMaxAge: 600000, // 10 minutes
|
|
39
|
+
timeout: 60000, // 60 seconds (increased from default 30s)
|
|
40
|
+
requestAgent: agent
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Validates that required configuration is present
|
|
45
|
+
*/
|
|
46
|
+
validateConfig() {
|
|
47
|
+
return !!(this.name && this.issuer && this.audience && this.jwksUri);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gets the signing key for token verification with retry logic
|
|
51
|
+
*/
|
|
52
|
+
getSigningKey(header, callback) {
|
|
53
|
+
this.getSigningKeyWithRetry(header, 3, 1000)
|
|
54
|
+
.then((key) => {
|
|
55
|
+
const signingKey = 'publicKey' in key ? key.publicKey : key.rsaPublicKey;
|
|
56
|
+
callback(null, signingKey);
|
|
57
|
+
})
|
|
58
|
+
.catch((err) => {
|
|
59
|
+
console.error(`Error getting signing key for provider ${this.name} after retries:`, err);
|
|
60
|
+
callback(err);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves signing key with exponential backoff retry logic
|
|
65
|
+
*/
|
|
66
|
+
async getSigningKeyWithRetry(header, maxRetries, initialDelayMs) {
|
|
67
|
+
let lastError;
|
|
68
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
69
|
+
try {
|
|
70
|
+
return await this.jwksClient.getSigningKey(header.kid);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
74
|
+
// Check if this is a connection error that's worth retrying
|
|
75
|
+
const isRetryableError = lastError.message.includes('socket hang up') ||
|
|
76
|
+
lastError.message.includes('ECONNRESET') ||
|
|
77
|
+
lastError.message.includes('ETIMEDOUT') ||
|
|
78
|
+
lastError.message.includes('ENOTFOUND') ||
|
|
79
|
+
lastError.message.includes('EAI_AGAIN');
|
|
80
|
+
if (!isRetryableError || attempt === maxRetries) {
|
|
81
|
+
throw lastError;
|
|
82
|
+
}
|
|
83
|
+
// Exponential backoff: wait longer between each retry
|
|
84
|
+
const delayMs = initialDelayMs * Math.pow(2, attempt);
|
|
85
|
+
console.warn(`Attempt ${attempt + 1}/${maxRetries + 1} failed for provider ${this.name}. ` +
|
|
86
|
+
`Retrying in ${delayMs}ms... Error: ${lastError.message}`);
|
|
87
|
+
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
throw lastError || new Error('Failed to retrieve signing key');
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Checks if a given issuer URL belongs to this provider
|
|
94
|
+
*/
|
|
95
|
+
matchesIssuer(issuer) {
|
|
96
|
+
// Handle trailing slashes and case sensitivity
|
|
97
|
+
const normalizedIssuer = issuer.toLowerCase().replace(/\/$/, '');
|
|
98
|
+
const normalizedProviderIssuer = this.issuer.toLowerCase().replace(/\/$/, '');
|
|
99
|
+
return normalizedIssuer === normalizedProviderIssuer;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=BaseAuthProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseAuthProvider.js","sourceRoot":"","sources":["../src/BaseAuthProvider.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,UAAU,CAAC;AAGlC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;GAIG;AACH,MAAM,OAAgB,gBAAgB;IAUpC,YAAY,MAA0B;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAEhC,8DAA8D;QAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;YAC5C,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC;gBACd,SAAS,EAAE,IAAI;gBACf,cAAc,EAAE,KAAK;gBACrB,UAAU,EAAE,EAAE;gBACd,cAAc,EAAE,EAAE;gBAClB,OAAO,EAAE,KAAK;aACf,CAAC;YACJ,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC;gBACb,SAAS,EAAE,IAAI;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AAgC,CAAC,CAAC;IACjE,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,MAAc;QAC1B,+CAA+C;QAC/C,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACjE,MAAM,wBAAwB,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC9E,OAAO,gBAAgB,KAAK,wBAAwB,CAAC;IACvD,CAAC;CAMF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { JwtHeader, JwtPayload, SigningKeyCallback } from 'jsonwebtoken';
|
|
2
|
+
import { AuthUserInfo } from '@memberjunction/core';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for authentication providers in MemberJunction
|
|
5
|
+
* Enables support for any OAuth 2.0/OIDC compliant provider
|
|
6
|
+
*/
|
|
7
|
+
export interface IAuthProvider {
|
|
8
|
+
/**
|
|
9
|
+
* Unique name identifier for this provider
|
|
10
|
+
*/
|
|
11
|
+
name: string;
|
|
12
|
+
/**
|
|
13
|
+
* The issuer URL for this provider (must match the 'iss' claim in tokens)
|
|
14
|
+
*/
|
|
15
|
+
issuer: string;
|
|
16
|
+
/**
|
|
17
|
+
* The expected audience for tokens from this provider
|
|
18
|
+
*/
|
|
19
|
+
audience: string;
|
|
20
|
+
/**
|
|
21
|
+
* The JWKS endpoint URL for retrieving signing keys
|
|
22
|
+
*/
|
|
23
|
+
jwksUri: string;
|
|
24
|
+
/**
|
|
25
|
+
* OAuth client ID for this provider (optional, used by OAuth proxy for upstream authentication)
|
|
26
|
+
*/
|
|
27
|
+
clientId?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Validates that the provider configuration is complete and valid
|
|
30
|
+
*/
|
|
31
|
+
validateConfig(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the signing key for token verification
|
|
34
|
+
*/
|
|
35
|
+
getSigningKey(header: JwtHeader, callback: SigningKeyCallback): void;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts user information from the JWT payload
|
|
38
|
+
* Different providers use different claim names
|
|
39
|
+
*/
|
|
40
|
+
extractUserInfo(payload: JwtPayload): AuthUserInfo;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a given issuer URL belongs to this provider
|
|
43
|
+
*/
|
|
44
|
+
matchesIssuer(issuer: string): boolean;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=IAuthProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IAuthProvider.d.ts","sourceRoot":"","sources":["../src/IAuthProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAAsB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAExE;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC;IAE1B;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAErE;;;OAGG;IACH,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,YAAY,CAAC;IAEnD;;OAEG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;CACxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IAuthProvider.js","sourceRoot":"","sources":["../src/IAuthProvider.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { IAuthProvider } from './IAuthProvider.js';
|
|
2
|
+
export { BaseAuthProvider } from './BaseAuthProvider.js';
|
|
3
|
+
export { AuthProviderFactory } from './AuthProviderFactory.js';
|
|
4
|
+
export { TokenExpiredError } from './tokenExpiredError.js';
|
|
5
|
+
export type { AuthProviderConfig, AuthUserInfo } from '@memberjunction/core';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JwtPayload } from 'jsonwebtoken';
|
|
2
|
+
import { AuthProviderConfig, AuthUserInfo } from '@memberjunction/core';
|
|
3
|
+
import { BaseAuthProvider } from '../BaseAuthProvider.js';
|
|
4
|
+
/**
|
|
5
|
+
* Auth0 authentication provider implementation
|
|
6
|
+
*/
|
|
7
|
+
export declare class Auth0Provider extends BaseAuthProvider {
|
|
8
|
+
constructor(config: AuthProviderConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Extracts user information from Auth0 JWT payload
|
|
11
|
+
*/
|
|
12
|
+
extractUserInfo(payload: JwtPayload): AuthUserInfo;
|
|
13
|
+
/**
|
|
14
|
+
* Validates Auth0-specific configuration
|
|
15
|
+
*/
|
|
16
|
+
validateConfig(): boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=Auth0Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Auth0Provider.d.ts","sourceRoot":"","sources":["../../src/providers/Auth0Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;GAEG;AACH,qBACa,aAAc,SAAQ,gBAAgB;gBACrC,MAAM,EAAE,kBAAkB;IAItC;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,YAAY;IAiBlD;;OAEG;IACH,cAAc,IAAI,OAAO;CAO1B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
11
|
+
import { BaseAuthProvider } from '../BaseAuthProvider.js';
|
|
12
|
+
/**
|
|
13
|
+
* Auth0 authentication provider implementation
|
|
14
|
+
*/
|
|
15
|
+
let Auth0Provider = class Auth0Provider extends BaseAuthProvider {
|
|
16
|
+
constructor(config) {
|
|
17
|
+
super(config);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Extracts user information from Auth0 JWT payload
|
|
21
|
+
*/
|
|
22
|
+
extractUserInfo(payload) {
|
|
23
|
+
// Auth0 uses standard OIDC claims
|
|
24
|
+
const email = payload.email;
|
|
25
|
+
const fullName = payload.name;
|
|
26
|
+
const firstName = payload.given_name;
|
|
27
|
+
const lastName = payload.family_name;
|
|
28
|
+
const preferredUsername = payload.preferred_username || email;
|
|
29
|
+
return {
|
|
30
|
+
email,
|
|
31
|
+
firstName: firstName || fullName?.split(' ')[0],
|
|
32
|
+
lastName: lastName || fullName?.split(' ')[1] || fullName?.split(' ')[0],
|
|
33
|
+
fullName,
|
|
34
|
+
preferredUsername
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validates Auth0-specific configuration
|
|
39
|
+
*/
|
|
40
|
+
validateConfig() {
|
|
41
|
+
const baseValid = super.validateConfig();
|
|
42
|
+
const hasClientId = !!this.config.clientId;
|
|
43
|
+
const hasDomain = !!this.config.domain;
|
|
44
|
+
return baseValid && hasClientId && hasDomain;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
Auth0Provider = __decorate([
|
|
48
|
+
RegisterClass(BaseAuthProvider, 'auth0'),
|
|
49
|
+
__metadata("design:paramtypes", [Object])
|
|
50
|
+
], Auth0Provider);
|
|
51
|
+
export { Auth0Provider };
|
|
52
|
+
//# sourceMappingURL=Auth0Provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Auth0Provider.js","sourceRoot":"","sources":["../../src/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C,gBAAgB,EAAE,OAAO,CAAC;;GAC5B,aAAa,CAmCzB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JwtPayload } from 'jsonwebtoken';
|
|
2
|
+
import { AuthProviderConfig, AuthUserInfo } from '@memberjunction/core';
|
|
3
|
+
import { BaseAuthProvider } from '../BaseAuthProvider.js';
|
|
4
|
+
/**
|
|
5
|
+
* AWS Cognito authentication provider implementation
|
|
6
|
+
*/
|
|
7
|
+
export declare class CognitoProvider extends BaseAuthProvider {
|
|
8
|
+
constructor(config: AuthProviderConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Extracts user information from Cognito JWT payload
|
|
11
|
+
*/
|
|
12
|
+
extractUserInfo(payload: JwtPayload): AuthUserInfo;
|
|
13
|
+
/**
|
|
14
|
+
* Validates Cognito-specific configuration
|
|
15
|
+
*/
|
|
16
|
+
validateConfig(): boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=CognitoProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CognitoProvider.d.ts","sourceRoot":"","sources":["../../src/providers/CognitoProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D;;GAEG;AACH,qBACa,eAAgB,SAAQ,gBAAgB;gBACvC,MAAM,EAAE,kBAAkB;IAItC;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,YAAY;IAoBlD;;OAEG;IACH,cAAc,IAAI,OAAO;CAQ1B"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
11
|
+
import { BaseAuthProvider } from '../BaseAuthProvider.js';
|
|
12
|
+
/**
|
|
13
|
+
* AWS Cognito authentication provider implementation
|
|
14
|
+
*/
|
|
15
|
+
let CognitoProvider = class CognitoProvider extends BaseAuthProvider {
|
|
16
|
+
constructor(config) {
|
|
17
|
+
super(config);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Extracts user information from Cognito JWT payload
|
|
21
|
+
*/
|
|
22
|
+
extractUserInfo(payload) {
|
|
23
|
+
// Cognito uses custom claims with 'cognito:' prefix for some fields
|
|
24
|
+
const email = payload.email ||
|
|
25
|
+
payload['cognito:username'];
|
|
26
|
+
const fullName = payload.name;
|
|
27
|
+
const firstName = payload.given_name;
|
|
28
|
+
const lastName = payload.family_name;
|
|
29
|
+
const preferredUsername = payload['cognito:username'] ||
|
|
30
|
+
payload.preferred_username ||
|
|
31
|
+
email;
|
|
32
|
+
return {
|
|
33
|
+
email,
|
|
34
|
+
firstName: firstName || fullName?.split(' ')[0],
|
|
35
|
+
lastName: lastName || fullName?.split(' ')[1] || fullName?.split(' ')[0],
|
|
36
|
+
fullName,
|
|
37
|
+
preferredUsername
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validates Cognito-specific configuration
|
|
42
|
+
*/
|
|
43
|
+
validateConfig() {
|
|
44
|
+
const baseValid = super.validateConfig();
|
|
45
|
+
const hasClientId = !!this.config.clientId;
|
|
46
|
+
const hasRegion = !!this.config.region;
|
|
47
|
+
const hasUserPoolId = !!this.config.userPoolId;
|
|
48
|
+
return baseValid && hasClientId && hasRegion && hasUserPoolId;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
CognitoProvider = __decorate([
|
|
52
|
+
RegisterClass(BaseAuthProvider, 'cognito'),
|
|
53
|
+
__metadata("design:paramtypes", [Object])
|
|
54
|
+
], CognitoProvider);
|
|
55
|
+
export { CognitoProvider };
|
|
56
|
+
//# sourceMappingURL=CognitoProvider.js.map
|