@flink-app/oidc-plugin 1.0.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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +846 -0
- package/dist/OidcInternalContext.d.ts +15 -0
- package/dist/OidcInternalContext.d.ts.map +1 -0
- package/dist/OidcInternalContext.js +2 -0
- package/dist/OidcPlugin.d.ts +77 -0
- package/dist/OidcPlugin.d.ts.map +1 -0
- package/dist/OidcPlugin.js +274 -0
- package/dist/OidcPluginContext.d.ts +73 -0
- package/dist/OidcPluginContext.d.ts.map +1 -0
- package/dist/OidcPluginContext.js +2 -0
- package/dist/OidcPluginOptions.d.ts +267 -0
- package/dist/OidcPluginOptions.d.ts.map +1 -0
- package/dist/OidcPluginOptions.js +2 -0
- package/dist/OidcProviderConfig.d.ts +77 -0
- package/dist/OidcProviderConfig.d.ts.map +1 -0
- package/dist/OidcProviderConfig.js +2 -0
- package/dist/handlers/CallbackOidc.d.ts +38 -0
- package/dist/handlers/CallbackOidc.d.ts.map +1 -0
- package/dist/handlers/CallbackOidc.js +219 -0
- package/dist/handlers/InitiateOidc.d.ts +35 -0
- package/dist/handlers/InitiateOidc.d.ts.map +1 -0
- package/dist/handlers/InitiateOidc.js +91 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/providers/OidcProvider.d.ts +90 -0
- package/dist/providers/OidcProvider.d.ts.map +1 -0
- package/dist/providers/OidcProvider.js +208 -0
- package/dist/providers/ProviderRegistry.d.ts +55 -0
- package/dist/providers/ProviderRegistry.d.ts.map +1 -0
- package/dist/providers/ProviderRegistry.js +94 -0
- package/dist/repos/OidcConnectionRepo.d.ts +75 -0
- package/dist/repos/OidcConnectionRepo.d.ts.map +1 -0
- package/dist/repos/OidcConnectionRepo.js +122 -0
- package/dist/repos/OidcSessionRepo.d.ts +57 -0
- package/dist/repos/OidcSessionRepo.d.ts.map +1 -0
- package/dist/repos/OidcSessionRepo.js +91 -0
- package/dist/schemas/CallbackRequest.d.ts +37 -0
- package/dist/schemas/CallbackRequest.d.ts.map +1 -0
- package/dist/schemas/CallbackRequest.js +2 -0
- package/dist/schemas/InitiateRequest.d.ts +17 -0
- package/dist/schemas/InitiateRequest.d.ts.map +1 -0
- package/dist/schemas/InitiateRequest.js +2 -0
- package/dist/schemas/OidcConnection.d.ts +69 -0
- package/dist/schemas/OidcConnection.d.ts.map +1 -0
- package/dist/schemas/OidcConnection.js +2 -0
- package/dist/schemas/OidcProfile.d.ts +69 -0
- package/dist/schemas/OidcProfile.d.ts.map +1 -0
- package/dist/schemas/OidcProfile.js +2 -0
- package/dist/schemas/OidcSession.d.ts +46 -0
- package/dist/schemas/OidcSession.d.ts.map +1 -0
- package/dist/schemas/OidcSession.js +2 -0
- package/dist/schemas/OidcTokenSet.d.ts +42 -0
- package/dist/schemas/OidcTokenSet.d.ts.map +1 -0
- package/dist/schemas/OidcTokenSet.js +2 -0
- package/dist/utils/claims-mapper.d.ts +46 -0
- package/dist/utils/claims-mapper.d.ts.map +1 -0
- package/dist/utils/claims-mapper.js +104 -0
- package/dist/utils/encryption-utils.d.ts +32 -0
- package/dist/utils/encryption-utils.d.ts.map +1 -0
- package/dist/utils/encryption-utils.js +82 -0
- package/dist/utils/error-utils.d.ts +65 -0
- package/dist/utils/error-utils.d.ts.map +1 -0
- package/dist/utils/error-utils.js +150 -0
- package/dist/utils/response-utils.d.ts +18 -0
- package/dist/utils/response-utils.d.ts.map +1 -0
- package/dist/utils/response-utils.js +42 -0
- package/dist/utils/state-utils.d.ts +36 -0
- package/dist/utils/state-utils.d.ts.map +1 -0
- package/dist/utils/state-utils.js +66 -0
- package/examples/basic-oidc.ts +151 -0
- package/examples/multi-provider.ts +146 -0
- package/package.json +44 -0
- package/spec/handlers/InitiateOidc.spec.ts +62 -0
- package/spec/helpers/reporter.ts +34 -0
- package/spec/helpers/test-helpers.ts +108 -0
- package/spec/plugin/OidcPlugin.spec.ts +126 -0
- package/spec/providers/ProviderRegistry.spec.ts +197 -0
- package/spec/repos/OidcConnectionRepo.spec.ts +257 -0
- package/spec/repos/OidcSessionRepo.spec.ts +196 -0
- package/spec/support/jasmine.json +7 -0
- package/spec/utils/claims-mapper.spec.ts +257 -0
- package/spec/utils/encryption-utils.spec.ts +126 -0
- package/spec/utils/error-utils.spec.ts +107 -0
- package/spec/utils/state-utils.spec.ts +102 -0
- package/src/OidcInternalContext.ts +15 -0
- package/src/OidcPlugin.ts +290 -0
- package/src/OidcPluginContext.ts +76 -0
- package/src/OidcPluginOptions.ts +286 -0
- package/src/OidcProviderConfig.ts +87 -0
- package/src/handlers/CallbackOidc.ts +257 -0
- package/src/handlers/InitiateOidc.ts +110 -0
- package/src/index.ts +38 -0
- package/src/providers/OidcProvider.ts +237 -0
- package/src/providers/ProviderRegistry.ts +107 -0
- package/src/repos/OidcConnectionRepo.ts +132 -0
- package/src/repos/OidcSessionRepo.ts +99 -0
- package/src/schemas/CallbackRequest.ts +41 -0
- package/src/schemas/InitiateRequest.ts +17 -0
- package/src/schemas/OidcConnection.ts +80 -0
- package/src/schemas/OidcProfile.ts +79 -0
- package/src/schemas/OidcSession.ts +52 -0
- package/src/schemas/OidcTokenSet.ts +47 -0
- package/src/utils/claims-mapper.ts +114 -0
- package/src/utils/encryption-utils.ts +92 -0
- package/src/utils/error-utils.ts +167 -0
- package/src/utils/response-utils.ts +41 -0
- package/src/utils/state-utils.ts +66 -0
- package/tsconfig.dist.json +9 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Db } from "mongodb";
|
|
2
|
+
import OidcConnection from "../schemas/OidcConnection";
|
|
3
|
+
/**
|
|
4
|
+
* Repository for OIDC connections
|
|
5
|
+
*
|
|
6
|
+
* Manages persistent connections between users and OIDC providers.
|
|
7
|
+
* Stores the mapping of app users to IdP subjects, and optionally
|
|
8
|
+
* stores encrypted tokens for API access.
|
|
9
|
+
*/
|
|
10
|
+
export default class OidcConnectionRepo {
|
|
11
|
+
private collection;
|
|
12
|
+
constructor(collectionName: string, db: Db);
|
|
13
|
+
/**
|
|
14
|
+
* Create a new OIDC connection
|
|
15
|
+
*
|
|
16
|
+
* @param connection - Connection data
|
|
17
|
+
* @returns Created connection with _id
|
|
18
|
+
*/
|
|
19
|
+
create(connection: Omit<OidcConnection, "_id">): Promise<OidcConnection>;
|
|
20
|
+
/**
|
|
21
|
+
* Find connection by user ID and provider
|
|
22
|
+
*
|
|
23
|
+
* @param userId - Application user ID
|
|
24
|
+
* @param provider - Provider name
|
|
25
|
+
* @returns Connection or null if not found
|
|
26
|
+
*/
|
|
27
|
+
findByUserAndProvider(userId: string, provider: string): Promise<OidcConnection | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Find connection by subject and issuer
|
|
30
|
+
*
|
|
31
|
+
* Used to look up users by their IdP identity.
|
|
32
|
+
*
|
|
33
|
+
* @param subject - OIDC subject (sub claim)
|
|
34
|
+
* @param issuer - OIDC issuer (iss claim)
|
|
35
|
+
* @returns Connection or null if not found
|
|
36
|
+
*/
|
|
37
|
+
findBySubjectAndIssuer(subject: string, issuer: string): Promise<OidcConnection | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Find all connections for a user
|
|
40
|
+
*
|
|
41
|
+
* @param userId - Application user ID
|
|
42
|
+
* @returns Array of connections
|
|
43
|
+
*/
|
|
44
|
+
findByUserId(userId: string): Promise<OidcConnection[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Update connection
|
|
47
|
+
*
|
|
48
|
+
* Typically used to update tokens when they're refreshed.
|
|
49
|
+
*
|
|
50
|
+
* @param connectionId - Connection _id
|
|
51
|
+
* @param updates - Fields to update
|
|
52
|
+
*/
|
|
53
|
+
updateOne(connectionId: string, updates: Partial<OidcConnection>): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Delete connection by user and provider
|
|
56
|
+
*
|
|
57
|
+
* @param userId - Application user ID
|
|
58
|
+
* @param provider - Provider name
|
|
59
|
+
*/
|
|
60
|
+
deleteByUserAndProvider(userId: string, provider: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Delete all connections for a user
|
|
63
|
+
*
|
|
64
|
+
* @param userId - Application user ID
|
|
65
|
+
*/
|
|
66
|
+
deleteByUserId(userId: string): Promise<number>;
|
|
67
|
+
/**
|
|
68
|
+
* Find one connection by query
|
|
69
|
+
*
|
|
70
|
+
* @param query - MongoDB query
|
|
71
|
+
* @returns Connection or null if not found
|
|
72
|
+
*/
|
|
73
|
+
getOne(query: Partial<OidcConnection>): Promise<OidcConnection | null>;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=OidcConnectionRepo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OidcConnectionRepo.d.ts","sourceRoot":"","sources":["../../src/repos/OidcConnectionRepo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,cAAc,MAAM,2BAA2B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IACnC,OAAO,CAAC,UAAU,CAA6B;gBAEnC,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE;IAI1C;;;;;OAKG;IACG,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;IAQ9E;;;;;;OAMG;IACG,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAW7F;;;;;;;;OAQG;IACG,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAW7F;;;;;OAKG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAQ7D;;;;;;;OAOG;IACG,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAItF;;;;;OAKG;IACG,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9E;;;;OAIG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKrD;;;;;OAKG;IACG,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;CAU/E"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Repository for OIDC connections
|
|
5
|
+
*
|
|
6
|
+
* Manages persistent connections between users and OIDC providers.
|
|
7
|
+
* Stores the mapping of app users to IdP subjects, and optionally
|
|
8
|
+
* stores encrypted tokens for API access.
|
|
9
|
+
*/
|
|
10
|
+
class OidcConnectionRepo {
|
|
11
|
+
constructor(collectionName, db) {
|
|
12
|
+
this.collection = db.collection(collectionName);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a new OIDC connection
|
|
16
|
+
*
|
|
17
|
+
* @param connection - Connection data
|
|
18
|
+
* @returns Created connection with _id
|
|
19
|
+
*/
|
|
20
|
+
async create(connection) {
|
|
21
|
+
const result = await this.collection.insertOne(connection);
|
|
22
|
+
return {
|
|
23
|
+
...connection,
|
|
24
|
+
_id: result.insertedId.toString(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Find connection by user ID and provider
|
|
29
|
+
*
|
|
30
|
+
* @param userId - Application user ID
|
|
31
|
+
* @param provider - Provider name
|
|
32
|
+
* @returns Connection or null if not found
|
|
33
|
+
*/
|
|
34
|
+
async findByUserAndProvider(userId, provider) {
|
|
35
|
+
const connection = await this.collection.findOne({ userId, provider });
|
|
36
|
+
if (!connection) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
...connection,
|
|
41
|
+
_id: connection._id?.toString(),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Find connection by subject and issuer
|
|
46
|
+
*
|
|
47
|
+
* Used to look up users by their IdP identity.
|
|
48
|
+
*
|
|
49
|
+
* @param subject - OIDC subject (sub claim)
|
|
50
|
+
* @param issuer - OIDC issuer (iss claim)
|
|
51
|
+
* @returns Connection or null if not found
|
|
52
|
+
*/
|
|
53
|
+
async findBySubjectAndIssuer(subject, issuer) {
|
|
54
|
+
const connection = await this.collection.findOne({ subject, issuer });
|
|
55
|
+
if (!connection) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
...connection,
|
|
60
|
+
_id: connection._id?.toString(),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Find all connections for a user
|
|
65
|
+
*
|
|
66
|
+
* @param userId - Application user ID
|
|
67
|
+
* @returns Array of connections
|
|
68
|
+
*/
|
|
69
|
+
async findByUserId(userId) {
|
|
70
|
+
const connections = await this.collection.find({ userId }).toArray();
|
|
71
|
+
return connections.map((conn) => ({
|
|
72
|
+
...conn,
|
|
73
|
+
_id: conn._id?.toString(),
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Update connection
|
|
78
|
+
*
|
|
79
|
+
* Typically used to update tokens when they're refreshed.
|
|
80
|
+
*
|
|
81
|
+
* @param connectionId - Connection _id
|
|
82
|
+
* @param updates - Fields to update
|
|
83
|
+
*/
|
|
84
|
+
async updateOne(connectionId, updates) {
|
|
85
|
+
await this.collection.updateOne({ _id: connectionId }, { $set: updates });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Delete connection by user and provider
|
|
89
|
+
*
|
|
90
|
+
* @param userId - Application user ID
|
|
91
|
+
* @param provider - Provider name
|
|
92
|
+
*/
|
|
93
|
+
async deleteByUserAndProvider(userId, provider) {
|
|
94
|
+
await this.collection.deleteOne({ userId, provider });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Delete all connections for a user
|
|
98
|
+
*
|
|
99
|
+
* @param userId - Application user ID
|
|
100
|
+
*/
|
|
101
|
+
async deleteByUserId(userId) {
|
|
102
|
+
const result = await this.collection.deleteMany({ userId });
|
|
103
|
+
return result.deletedCount;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Find one connection by query
|
|
107
|
+
*
|
|
108
|
+
* @param query - MongoDB query
|
|
109
|
+
* @returns Connection or null if not found
|
|
110
|
+
*/
|
|
111
|
+
async getOne(query) {
|
|
112
|
+
const connection = await this.collection.findOne(query);
|
|
113
|
+
if (!connection) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
...connection,
|
|
118
|
+
_id: connection._id?.toString(),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.default = OidcConnectionRepo;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Db } from "mongodb";
|
|
2
|
+
import OidcSession from "../schemas/OidcSession";
|
|
3
|
+
/**
|
|
4
|
+
* Repository for OIDC sessions
|
|
5
|
+
*
|
|
6
|
+
* Manages temporary sessions during the OIDC authorization flow.
|
|
7
|
+
* Sessions are automatically deleted by MongoDB TTL index after expiration.
|
|
8
|
+
*/
|
|
9
|
+
export default class OidcSessionRepo {
|
|
10
|
+
private collection;
|
|
11
|
+
constructor(collectionName: string, db: Db);
|
|
12
|
+
/**
|
|
13
|
+
* Create a new OIDC session
|
|
14
|
+
*
|
|
15
|
+
* @param session - Session data
|
|
16
|
+
* @returns Created session with _id
|
|
17
|
+
*/
|
|
18
|
+
create(session: Omit<OidcSession, "_id">): Promise<OidcSession>;
|
|
19
|
+
/**
|
|
20
|
+
* Find session by state parameter
|
|
21
|
+
*
|
|
22
|
+
* Used during callback to validate the state and retrieve session data.
|
|
23
|
+
*
|
|
24
|
+
* @param state - State parameter from callback
|
|
25
|
+
* @returns Session or null if not found
|
|
26
|
+
*/
|
|
27
|
+
getByState(state: string): Promise<OidcSession | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Find one session by query
|
|
30
|
+
*
|
|
31
|
+
* @param query - MongoDB query
|
|
32
|
+
* @returns Session or null if not found
|
|
33
|
+
*/
|
|
34
|
+
getOne(query: Partial<OidcSession>): Promise<OidcSession | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Delete session by session ID
|
|
37
|
+
*
|
|
38
|
+
* Sessions are one-time use - delete after successful validation.
|
|
39
|
+
*
|
|
40
|
+
* @param sessionId - Session identifier
|
|
41
|
+
*/
|
|
42
|
+
deleteBySessionId(sessionId: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Delete session by state
|
|
45
|
+
*
|
|
46
|
+
* @param state - State parameter
|
|
47
|
+
*/
|
|
48
|
+
deleteByState(state: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Delete all expired sessions
|
|
51
|
+
*
|
|
52
|
+
* This is handled automatically by MongoDB TTL index,
|
|
53
|
+
* but can be called manually for testing or cleanup.
|
|
54
|
+
*/
|
|
55
|
+
deleteExpired(): Promise<number>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=OidcSessionRepo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OidcSessionRepo.d.ts","sourceRoot":"","sources":["../../src/repos/OidcSessionRepo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,WAAW,MAAM,wBAAwB,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,eAAe;IAChC,OAAO,CAAC,UAAU,CAA0B;gBAEhC,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE;IAI1C;;;;;OAKG;IACG,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAQrE;;;;;;;OAOG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAW5D;;;;;OAKG;IACG,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAWtE;;;;;;OAMG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD;;;;OAIG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD;;;;;OAKG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAMzC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Repository for OIDC sessions
|
|
5
|
+
*
|
|
6
|
+
* Manages temporary sessions during the OIDC authorization flow.
|
|
7
|
+
* Sessions are automatically deleted by MongoDB TTL index after expiration.
|
|
8
|
+
*/
|
|
9
|
+
class OidcSessionRepo {
|
|
10
|
+
constructor(collectionName, db) {
|
|
11
|
+
this.collection = db.collection(collectionName);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a new OIDC session
|
|
15
|
+
*
|
|
16
|
+
* @param session - Session data
|
|
17
|
+
* @returns Created session with _id
|
|
18
|
+
*/
|
|
19
|
+
async create(session) {
|
|
20
|
+
const result = await this.collection.insertOne(session);
|
|
21
|
+
return {
|
|
22
|
+
...session,
|
|
23
|
+
_id: result.insertedId.toString(),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Find session by state parameter
|
|
28
|
+
*
|
|
29
|
+
* Used during callback to validate the state and retrieve session data.
|
|
30
|
+
*
|
|
31
|
+
* @param state - State parameter from callback
|
|
32
|
+
* @returns Session or null if not found
|
|
33
|
+
*/
|
|
34
|
+
async getByState(state) {
|
|
35
|
+
const session = await this.collection.findOne({ state });
|
|
36
|
+
if (!session) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
...session,
|
|
41
|
+
_id: session._id?.toString(),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Find one session by query
|
|
46
|
+
*
|
|
47
|
+
* @param query - MongoDB query
|
|
48
|
+
* @returns Session or null if not found
|
|
49
|
+
*/
|
|
50
|
+
async getOne(query) {
|
|
51
|
+
const session = await this.collection.findOne(query);
|
|
52
|
+
if (!session) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
...session,
|
|
57
|
+
_id: session._id?.toString(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Delete session by session ID
|
|
62
|
+
*
|
|
63
|
+
* Sessions are one-time use - delete after successful validation.
|
|
64
|
+
*
|
|
65
|
+
* @param sessionId - Session identifier
|
|
66
|
+
*/
|
|
67
|
+
async deleteBySessionId(sessionId) {
|
|
68
|
+
await this.collection.deleteOne({ sessionId });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Delete session by state
|
|
72
|
+
*
|
|
73
|
+
* @param state - State parameter
|
|
74
|
+
*/
|
|
75
|
+
async deleteByState(state) {
|
|
76
|
+
await this.collection.deleteOne({ state });
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Delete all expired sessions
|
|
80
|
+
*
|
|
81
|
+
* This is handled automatically by MongoDB TTL index,
|
|
82
|
+
* but can be called manually for testing or cleanup.
|
|
83
|
+
*/
|
|
84
|
+
async deleteExpired() {
|
|
85
|
+
const result = await this.collection.deleteMany({
|
|
86
|
+
createdAt: { $lt: new Date(Date.now() - 600000) }, // 10 minutes
|
|
87
|
+
});
|
|
88
|
+
return result.deletedCount;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.default = OidcSessionRepo;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query parameters for the OIDC callback endpoint
|
|
3
|
+
*
|
|
4
|
+
* GET /oidc/:provider/callback?code=...&state=...&response_type=json
|
|
5
|
+
*/
|
|
6
|
+
export default interface CallbackRequest {
|
|
7
|
+
/**
|
|
8
|
+
* Authorization code from the IdP
|
|
9
|
+
* Required for successful authentication
|
|
10
|
+
*/
|
|
11
|
+
code?: string;
|
|
12
|
+
/**
|
|
13
|
+
* State parameter for CSRF protection
|
|
14
|
+
* Must match the state stored in the session
|
|
15
|
+
*/
|
|
16
|
+
state?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Error code from the IdP (if authorization failed)
|
|
19
|
+
* e.g., "access_denied" if user cancelled
|
|
20
|
+
*/
|
|
21
|
+
error?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Human-readable error description from the IdP
|
|
24
|
+
*/
|
|
25
|
+
error_description?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Response format for the callback
|
|
28
|
+
* - "json": Return JSON response with user and token
|
|
29
|
+
* - undefined: Redirect to redirectUri with token in URL fragment
|
|
30
|
+
*/
|
|
31
|
+
response_type?: "json";
|
|
32
|
+
/**
|
|
33
|
+
* Index signature for Flink Query type compatibility
|
|
34
|
+
*/
|
|
35
|
+
[key: string]: string | string[] | undefined;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=CallbackRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CallbackRequest.d.ts","sourceRoot":"","sources":["../../src/schemas/CallbackRequest.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,eAAe;IACpC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;CAChD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query parameters for the OIDC initiate endpoint
|
|
3
|
+
*
|
|
4
|
+
* GET /oidc/:provider/initiate?redirectUri=...
|
|
5
|
+
*/
|
|
6
|
+
export default interface InitiateRequest {
|
|
7
|
+
/**
|
|
8
|
+
* Optional redirect URI after successful authentication
|
|
9
|
+
* If not provided, uses the default callbackUrl from provider config
|
|
10
|
+
*/
|
|
11
|
+
redirectUri?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Index signature for Flink Query type compatibility
|
|
14
|
+
*/
|
|
15
|
+
[key: string]: string | string[] | undefined;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=InitiateRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitiateRequest.d.ts","sourceRoot":"","sources":["../../src/schemas/InitiateRequest.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,eAAe;IACpC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;CAChD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OIDC connection linking a user to an IdP
|
|
3
|
+
*
|
|
4
|
+
* Persistent record of the user's connection to an OIDC provider.
|
|
5
|
+
* Stores the mapping between the app's user and the IdP's subject identifier.
|
|
6
|
+
* Optionally stores encrypted OAuth tokens if storeTokens is enabled.
|
|
7
|
+
*/
|
|
8
|
+
export default interface OidcConnection {
|
|
9
|
+
/**
|
|
10
|
+
* MongoDB document ID
|
|
11
|
+
*/
|
|
12
|
+
_id?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Application user ID
|
|
15
|
+
* References the user in your app's user collection
|
|
16
|
+
*/
|
|
17
|
+
userId: string;
|
|
18
|
+
/**
|
|
19
|
+
* OIDC provider name (e.g., "acme", "contoso")
|
|
20
|
+
*/
|
|
21
|
+
provider: string;
|
|
22
|
+
/**
|
|
23
|
+
* OIDC subject identifier from the IdP
|
|
24
|
+
* The 'sub' claim from the ID token - unique per user per IdP
|
|
25
|
+
*/
|
|
26
|
+
subject: string;
|
|
27
|
+
/**
|
|
28
|
+
* OIDC issuer identifier
|
|
29
|
+
* The 'iss' claim from the ID token - identifies the IdP
|
|
30
|
+
*/
|
|
31
|
+
issuer: string;
|
|
32
|
+
/**
|
|
33
|
+
* User's email from the IdP
|
|
34
|
+
* Optional - for reference and display
|
|
35
|
+
*/
|
|
36
|
+
email?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Encrypted access token (if storeTokens enabled)
|
|
39
|
+
* Used to call IdP APIs on behalf of the user
|
|
40
|
+
*/
|
|
41
|
+
accessToken?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Encrypted refresh token (if storeTokens enabled)
|
|
44
|
+
* Used to obtain new access tokens
|
|
45
|
+
*/
|
|
46
|
+
refreshToken?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Encrypted ID token (if storeTokens enabled)
|
|
49
|
+
* The JWT containing user claims
|
|
50
|
+
*/
|
|
51
|
+
idToken?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Space-separated list of granted scopes
|
|
54
|
+
*/
|
|
55
|
+
scope?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Access token expiration time
|
|
58
|
+
*/
|
|
59
|
+
expiresAt?: Date;
|
|
60
|
+
/**
|
|
61
|
+
* Connection creation timestamp
|
|
62
|
+
*/
|
|
63
|
+
createdAt: Date;
|
|
64
|
+
/**
|
|
65
|
+
* Last update timestamp
|
|
66
|
+
*/
|
|
67
|
+
updatedAt: Date;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=OidcConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OidcConnection.d.ts","sourceRoot":"","sources":["../../src/schemas/OidcConnection.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,WAAW,cAAc;IACnC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;CACnB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalized user profile from OIDC ID token and UserInfo endpoint
|
|
3
|
+
*
|
|
4
|
+
* This is the standardized profile format passed to the onAuthSuccess callback.
|
|
5
|
+
* Maps OIDC standard claims to a consistent profile structure.
|
|
6
|
+
*/
|
|
7
|
+
export default interface OidcProfile {
|
|
8
|
+
/**
|
|
9
|
+
* Subject identifier - unique user ID from the IdP
|
|
10
|
+
* OIDC standard claim: 'sub'
|
|
11
|
+
*/
|
|
12
|
+
id: string;
|
|
13
|
+
/**
|
|
14
|
+
* User's email address
|
|
15
|
+
* OIDC standard claim: 'email'
|
|
16
|
+
*/
|
|
17
|
+
email: string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the email has been verified by the IdP
|
|
20
|
+
* OIDC standard claim: 'email_verified'
|
|
21
|
+
*/
|
|
22
|
+
emailVerified?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* User's full name
|
|
25
|
+
* OIDC standard claim: 'name'
|
|
26
|
+
*/
|
|
27
|
+
name?: string;
|
|
28
|
+
/**
|
|
29
|
+
* User's given name (first name)
|
|
30
|
+
* OIDC standard claim: 'given_name'
|
|
31
|
+
*/
|
|
32
|
+
givenName?: string;
|
|
33
|
+
/**
|
|
34
|
+
* User's family name (last name)
|
|
35
|
+
* OIDC standard claim: 'family_name'
|
|
36
|
+
*/
|
|
37
|
+
familyName?: string;
|
|
38
|
+
/**
|
|
39
|
+
* User's middle name
|
|
40
|
+
* OIDC standard claim: 'middle_name'
|
|
41
|
+
*/
|
|
42
|
+
middleName?: string;
|
|
43
|
+
/**
|
|
44
|
+
* User's preferred username
|
|
45
|
+
* OIDC standard claim: 'preferred_username'
|
|
46
|
+
*/
|
|
47
|
+
username?: string;
|
|
48
|
+
/**
|
|
49
|
+
* URL of the user's profile picture
|
|
50
|
+
* OIDC standard claim: 'picture'
|
|
51
|
+
*/
|
|
52
|
+
picture?: string;
|
|
53
|
+
/**
|
|
54
|
+
* User's phone number
|
|
55
|
+
* OIDC standard claim: 'phone_number'
|
|
56
|
+
*/
|
|
57
|
+
phoneNumber?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the phone number has been verified
|
|
60
|
+
* OIDC standard claim: 'phone_number_verified'
|
|
61
|
+
*/
|
|
62
|
+
phoneNumberVerified?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Raw OIDC claims from ID token and UserInfo
|
|
65
|
+
* Contains all claims returned by the IdP
|
|
66
|
+
*/
|
|
67
|
+
raw: Record<string, any>;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=OidcProfile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OidcProfile.d.ts","sourceRoot":"","sources":["../../src/schemas/OidcProfile.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,WAAW;IAChC;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC5B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OIDC session stored during the authorization flow
|
|
3
|
+
*
|
|
4
|
+
* Temporary session that exists only during the OAuth/OIDC flow (typically 10 minutes).
|
|
5
|
+
* Used for CSRF protection (state), PKCE (codeVerifier), and replay protection (nonce).
|
|
6
|
+
*/
|
|
7
|
+
export default interface OidcSession {
|
|
8
|
+
/**
|
|
9
|
+
* MongoDB document ID
|
|
10
|
+
*/
|
|
11
|
+
_id?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Unique session identifier
|
|
14
|
+
*/
|
|
15
|
+
sessionId: string;
|
|
16
|
+
/**
|
|
17
|
+
* CSRF protection token
|
|
18
|
+
* Random value used to prevent cross-site request forgery attacks
|
|
19
|
+
*/
|
|
20
|
+
state: string;
|
|
21
|
+
/**
|
|
22
|
+
* PKCE code verifier
|
|
23
|
+
* Secret value used to prove the client initiated the authorization request
|
|
24
|
+
*/
|
|
25
|
+
codeVerifier: string;
|
|
26
|
+
/**
|
|
27
|
+
* Nonce for ID token validation
|
|
28
|
+
* Random value used to prevent replay attacks on the ID token
|
|
29
|
+
*/
|
|
30
|
+
nonce: string;
|
|
31
|
+
/**
|
|
32
|
+
* Provider name (e.g., "acme", "contoso")
|
|
33
|
+
*/
|
|
34
|
+
provider: string;
|
|
35
|
+
/**
|
|
36
|
+
* URL to redirect to after successful authentication
|
|
37
|
+
* Can be overridden by the client via query parameter
|
|
38
|
+
*/
|
|
39
|
+
redirectUri: string;
|
|
40
|
+
/**
|
|
41
|
+
* Session creation timestamp
|
|
42
|
+
* MongoDB TTL index will automatically delete expired sessions
|
|
43
|
+
*/
|
|
44
|
+
createdAt: Date;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=OidcSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OidcSession.d.ts","sourceRoot":"","sources":["../../src/schemas/OidcSession.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,WAAW,WAAW;IAChC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,SAAS,EAAE,IAAI,CAAC;CACnB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OIDC token set returned from the token endpoint
|
|
3
|
+
*
|
|
4
|
+
* Contains the tokens issued by the IdP after successful authorization.
|
|
5
|
+
*/
|
|
6
|
+
export default interface OidcTokenSet {
|
|
7
|
+
/**
|
|
8
|
+
* Access token for calling IdP APIs
|
|
9
|
+
* Used to access protected resources at the IdP
|
|
10
|
+
*/
|
|
11
|
+
accessToken: string;
|
|
12
|
+
/**
|
|
13
|
+
* ID token (JWT) containing user claims
|
|
14
|
+
* This is the core OIDC token that contains user identity information
|
|
15
|
+
*/
|
|
16
|
+
idToken: string;
|
|
17
|
+
/**
|
|
18
|
+
* Refresh token for obtaining new access tokens
|
|
19
|
+
* Optional - only if IdP supports and grants refresh tokens
|
|
20
|
+
*/
|
|
21
|
+
refreshToken?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Token type (usually "Bearer")
|
|
24
|
+
*/
|
|
25
|
+
tokenType: string;
|
|
26
|
+
/**
|
|
27
|
+
* Expiration time in seconds
|
|
28
|
+
* How many seconds until the access token expires
|
|
29
|
+
*/
|
|
30
|
+
expiresIn?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Scope granted by the IdP
|
|
33
|
+
* Space-separated list of scopes
|
|
34
|
+
*/
|
|
35
|
+
scope?: string;
|
|
36
|
+
/**
|
|
37
|
+
* All claims from the ID token
|
|
38
|
+
* Parsed and validated JWT claims
|
|
39
|
+
*/
|
|
40
|
+
claims: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=OidcTokenSet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OidcTokenSet.d.ts","sourceRoot":"","sources":["../../src/schemas/OidcTokenSet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,YAAY;IACjC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B"}
|