@connectid-tools/rp-nodejs-sdk 4.2.1 → 5.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/README.md +60 -71
- package/package.json +4 -5
- package/{config.js → src/config.js} +2 -31
- package/src/conformance/api/conformance-api.d.ts +38 -0
- package/src/conformance/api/conformance-api.js +53 -0
- package/src/conformance/config.json +60 -0
- package/src/conformance/conformance-config.d.ts +2 -0
- package/src/conformance/conformance-config.js +34 -0
- package/src/conformance/conformance.test.js +101 -0
- package/src/conformance/variant.json +1 -0
- package/src/crypto/crypto-loader.d.ts +32 -0
- package/src/crypto/crypto-loader.js +49 -0
- package/src/crypto/jwt-helper.d.ts +61 -0
- package/src/crypto/jwt-helper.js +92 -0
- package/src/crypto/pkce-helper.d.ts +43 -0
- package/src/crypto/pkce-helper.js +75 -0
- package/src/endpoints/participants-endpoint.d.ts +55 -0
- package/src/endpoints/participants-endpoint.js +137 -0
- package/src/endpoints/pushed-authorisation-request-endpoint.d.ts +87 -0
- package/src/endpoints/pushed-authorisation-request-endpoint.js +192 -0
- package/src/endpoints/retrieve-token-endpoint.d.ts +66 -0
- package/src/endpoints/retrieve-token-endpoint.js +159 -0
- package/src/endpoints/userinfo-endpoint.d.ts +24 -0
- package/src/endpoints/userinfo-endpoint.js +50 -0
- package/src/fapi/fapi-utils.d.ts +6 -0
- package/src/fapi/fapi-utils.js +9 -0
- package/src/http/http-client-extensions.d.ts +60 -0
- package/src/http/http-client-extensions.js +106 -0
- package/src/http/http-client-factory.d.ts +27 -0
- package/src/http/http-client-factory.js +45 -0
- package/src/integration/integration.test.d.ts +1 -0
- package/src/integration/integration.test.js +30 -0
- package/src/model/callback-params.d.ts +31 -0
- package/src/model/callback-params.js +1 -0
- package/src/model/claims.d.ts +100 -0
- package/src/model/claims.js +1 -0
- package/src/model/consolidated-token-set.d.ts +74 -0
- package/src/model/consolidated-token-set.js +100 -0
- package/src/model/discovery-service.d.ts +46 -0
- package/src/model/discovery-service.js +112 -0
- package/src/model/issuer-metadata.d.ts +165 -0
- package/src/model/issuer-metadata.js +1 -0
- package/src/model/jwks.d.ts +12 -0
- package/src/model/jwks.js +1 -0
- package/src/model/token-response.d.ts +31 -0
- package/src/model/token-response.js +1 -0
- package/src/model/token-set.d.ts +73 -0
- package/src/model/token-set.js +179 -0
- package/src/relying-party-client-sdk.d.ts +68 -0
- package/src/relying-party-client-sdk.js +150 -0
- package/src/test-data/large-participants-test-data.d.ts +865 -0
- package/src/test-data/large-participants-test-data.js +18907 -0
- package/src/test-data/participants-test-data.d.ts +149 -0
- package/src/test-data/participants-test-data.js +458 -0
- package/src/test-data/sandbox-participants-test-data.d.ts +865 -0
- package/src/test-data/sandbox-participants-test-data.js +3794 -0
- package/src/tests/cert-utils.test.d.ts +1 -0
- package/src/tests/cert-utils.test.js +13 -0
- package/src/tests/functional-utils.test.d.ts +1 -0
- package/src/tests/functional-utils.test.js +13 -0
- package/src/tests/participant-filters.test.d.ts +1 -0
- package/src/tests/participant-filters.test.js +151 -0
- package/src/tests/pushed-authorisation-request-endpoint.test.d.ts +1 -0
- package/src/tests/pushed-authorisation-request-endpoint.test.js +159 -0
- package/src/tests/relying-party-client-sdk.test.d.ts +1 -0
- package/src/tests/relying-party-client-sdk.test.js +313 -0
- package/src/tests/request-utils.test.d.ts +1 -0
- package/src/tests/request-utils.test.js +16 -0
- package/src/tests/system-information.test.d.ts +1 -0
- package/src/tests/system-information.test.js +16 -0
- package/src/tests/user-agent.test.d.ts +1 -0
- package/src/tests/user-agent.test.js +23 -0
- package/src/tests/validator.test.d.ts +1 -0
- package/src/tests/validator.test.js +38 -0
- package/{types.d.ts → src/types.d.ts} +61 -32
- package/src/types.js +1 -0
- package/{utils → src/utils}/request-utils.d.ts +1 -1
- package/src/utils/request-utils.js +8 -0
- package/{utils → src/utils}/user-agent.d.ts +1 -1
- package/{utils → src/utils}/user-agent.js +1 -1
- package/relying-party-client-sdk.d.ts +0 -37
- package/relying-party-client-sdk.js +0 -364
- package/utils/request-utils.js +0 -8
- /package/{config.d.ts → src/config.d.ts} +0 -0
- /package/{types.js → src/conformance/conformance.test.d.ts} +0 -0
- /package/{filter → src/filter}/participant-filters.d.ts +0 -0
- /package/{filter → src/filter}/participant-filters.js +0 -0
- /package/{logger.d.ts → src/logger.d.ts} +0 -0
- /package/{logger.js → src/logger.js} +0 -0
- /package/{utils → src/utils}/cert-utils.d.ts +0 -0
- /package/{utils → src/utils}/cert-utils.js +0 -0
- /package/{utils → src/utils}/functional-utils.d.ts +0 -0
- /package/{utils → src/utils}/functional-utils.js +0 -0
- /package/{utils → src/utils}/system-information.d.ts +0 -0
- /package/{utils → src/utils}/system-information.js +0 -0
- /package/{validator.d.ts → src/validator.d.ts} +0 -0
- /package/{validator.js → src/validator.js} +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { getCertificate } from './utils/cert-utils.js';
|
|
2
|
+
import { getLogger } from './logger.js';
|
|
3
|
+
import ParticipantFilters from './filter/participant-filters.js';
|
|
4
|
+
import { illegalPurposeChars, isValidCertificate, validatePurpose } from './validator.js';
|
|
5
|
+
import { CryptoLoader } from './crypto/crypto-loader.js';
|
|
6
|
+
import { JwtHelper } from './crypto/jwt-helper.js';
|
|
7
|
+
import { HttpClientFactory } from './http/http-client-factory.js';
|
|
8
|
+
import { ParticipantsEndpoint } from './endpoints/participants-endpoint.js';
|
|
9
|
+
import { PushedAuthorisationRequestEndpoint } from './endpoints/pushed-authorisation-request-endpoint.js';
|
|
10
|
+
import { RetrieveTokenEndpoint } from './endpoints/retrieve-token-endpoint.js';
|
|
11
|
+
import { UserInfoEndpoint } from './endpoints/userinfo-endpoint.js';
|
|
12
|
+
export default class RelyingPartyClientSdk {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.purpose = 'verifying your identity';
|
|
15
|
+
this.config = config;
|
|
16
|
+
// Validate certificates
|
|
17
|
+
if (!isValidCertificate(this.config.data.transport_key, this.config.data.transport_key_content)) {
|
|
18
|
+
throw new Error('Either transport_key or transport_key_content must be provided');
|
|
19
|
+
}
|
|
20
|
+
if (!isValidCertificate(this.config.data.transport_pem, this.config.data.transport_pem_content)) {
|
|
21
|
+
throw new Error('Either transport_pem or transport_pem_content must be provided');
|
|
22
|
+
}
|
|
23
|
+
if (!isValidCertificate(this.config.data.signing_key, this.config.data.signing_key_content)) {
|
|
24
|
+
throw new Error('Either signing_key or signing_key_content must be provided');
|
|
25
|
+
}
|
|
26
|
+
if (!isValidCertificate(this.config.data.ca_pem, this.config.data.ca_pem_content)) {
|
|
27
|
+
throw new Error('Either ca_pem or ca_pem_content must be provided');
|
|
28
|
+
}
|
|
29
|
+
this.logger = getLogger(this.config.data.log_level);
|
|
30
|
+
this.logger.info(`Creating RelyingPartyClientSdk - version ${process.env.SDK_VERSION}`);
|
|
31
|
+
// Validate and set purpose
|
|
32
|
+
if (this.config.data.purpose) {
|
|
33
|
+
const purposeValidation = validatePurpose(this.config.data.purpose);
|
|
34
|
+
if (purposeValidation === 'INVALID_LENGTH') {
|
|
35
|
+
this.logger.warn('Purpose must be between 3 and 300 characters');
|
|
36
|
+
throw new Error(`Invalid purpose supplied in config: ${this.config.data.purpose}`);
|
|
37
|
+
}
|
|
38
|
+
if (purposeValidation === 'INVALID_CHARACTERS') {
|
|
39
|
+
this.logger.warn(`Purpose cannot contain any of the following characters: ${illegalPurposeChars.join(',')}, purpose supplied: [${this.config.data.purpose}]`);
|
|
40
|
+
throw new Error(`Invalid purpose supplied in config: ${this.config.data.purpose}`);
|
|
41
|
+
}
|
|
42
|
+
this.purpose = this.config.data.purpose;
|
|
43
|
+
this.logger.info(`Using default purpose supplied in config: ${this.purpose}`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.logger.info(`Using built-in default purpose: ${this.purpose}`);
|
|
47
|
+
}
|
|
48
|
+
// Log filtering configuration
|
|
49
|
+
if (this.config.data.include_uncertified_participants) {
|
|
50
|
+
this.logger.info('Identity provider list will not be filtered as include_uncertified_participants=true');
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
if (this.config.data.required_claims) {
|
|
54
|
+
this.logger.info(`Identity provider list will be filtered for participants that support the following claims: ${JSON.stringify(this.config.data.required_claims)}`);
|
|
55
|
+
}
|
|
56
|
+
if (this.config.data.required_participant_certifications) {
|
|
57
|
+
this.logger.info(`Identity provider list will be filtered for participants that support the following certifications: ${JSON.stringify(this.config.data.required_participant_certifications)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Log certificate source
|
|
61
|
+
this.logger.info(`Using ${this.config.data.transport_key_content ? 'transport_key_content' : 'transport_key'} config prop`);
|
|
62
|
+
this.logger.info(`Using ${this.config.data.transport_pem_content ? 'transport_pem_content' : 'transport_pem'} config prop`);
|
|
63
|
+
this.logger.info(`Using ${this.config.data.ca_pem_content ? 'ca_pem_content' : 'ca_pem'} config prop`);
|
|
64
|
+
this.logger.info(`Using ${this.config.data.signing_key_content ? 'signing_key_content' : 'signing_key'} config prop`);
|
|
65
|
+
// Initialize crypto
|
|
66
|
+
const signingKeyObject = CryptoLoader.loadPrivateKey(getCertificate(this.config.data.signing_key, this.config.data.signing_key_content));
|
|
67
|
+
// Initialize JWT helper
|
|
68
|
+
this.jwtHelper = new JwtHelper(signingKeyObject, this.config.data.signing_kid, this.config.data.client_id);
|
|
69
|
+
// Initialize HTTP client
|
|
70
|
+
this.httpClient = HttpClientFactory.createClient({
|
|
71
|
+
transportKey: getCertificate(this.config.data.transport_key, this.config.data.transport_key_content),
|
|
72
|
+
transportPem: getCertificate(this.config.data.transport_pem, this.config.data.transport_pem_content),
|
|
73
|
+
caPem: getCertificate(this.config.data.ca_pem, this.config.data.ca_pem_content),
|
|
74
|
+
clientId: this.config.data.client_id,
|
|
75
|
+
});
|
|
76
|
+
// Initialize endpoints
|
|
77
|
+
this.participantsEndpoint = new ParticipantsEndpoint(this.config, new ParticipantFilters(), this.httpClient, this.logger, () => this.getCurrentDate());
|
|
78
|
+
this.pushedAuthorisationRequestEndpoint = new PushedAuthorisationRequestEndpoint(this.config, this.httpClient, this.jwtHelper, this.logger, this.participantsEndpoint);
|
|
79
|
+
this.retrieveTokenEndpoint = new RetrieveTokenEndpoint(this.config, this.httpClient, this.jwtHelper, this.logger, this.participantsEndpoint);
|
|
80
|
+
this.userInfoEndpoint = new UserInfoEndpoint(this.httpClient, this.logger, this.config.data.client_id, this.participantsEndpoint);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the list of participating identity providers within the scheme.
|
|
84
|
+
*
|
|
85
|
+
* Applies filtering based on SDK configuration.
|
|
86
|
+
*
|
|
87
|
+
* @returns List of participants
|
|
88
|
+
*/
|
|
89
|
+
async getParticipants() {
|
|
90
|
+
return this.participantsEndpoint.getParticipants();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the list of fallback provider participants.
|
|
94
|
+
*
|
|
95
|
+
* @returns List of fallback provider participants
|
|
96
|
+
*/
|
|
97
|
+
async getFallbackProviderParticipants() {
|
|
98
|
+
return this.participantsEndpoint.getFallbackProviderParticipants();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Sends a Pushed Authorization Request (PAR).
|
|
102
|
+
*
|
|
103
|
+
* @param authServerId - Authorization server ID
|
|
104
|
+
* @param essentialClaims - Claims that must be provided
|
|
105
|
+
* @param voluntaryClaims - Claims that are optional
|
|
106
|
+
* @param purpose - Purpose string for data sharing
|
|
107
|
+
* @returns Object containing authorization URL and PKCE parameters
|
|
108
|
+
*/
|
|
109
|
+
async sendPushedAuthorisationRequest(authServerId, essentialClaims, voluntaryClaims = [], purpose = this.purpose) {
|
|
110
|
+
const { authUrl, codeVerifier, state, nonce, xFapiInteractionId } = await this.pushedAuthorisationRequestEndpoint.sendPushedAuthorisationRequest(authServerId, essentialClaims, voluntaryClaims, purpose);
|
|
111
|
+
return {
|
|
112
|
+
authUrl,
|
|
113
|
+
codeVerifier,
|
|
114
|
+
state,
|
|
115
|
+
nonce,
|
|
116
|
+
xFapiInteractionId,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Retrieves tokens using an authorisation code.
|
|
121
|
+
*
|
|
122
|
+
* @param authorisationServerId - Authorisation server ID
|
|
123
|
+
* @param requestParams - OAuth callback parameters
|
|
124
|
+
* @param codeVerifier - PKCE code verifier from PAR
|
|
125
|
+
* @param state - State parameter from PAR
|
|
126
|
+
* @param nonce - Nonce parameter from PAR
|
|
127
|
+
* @returns Consolidated token set with validated claims
|
|
128
|
+
*/
|
|
129
|
+
async retrieveTokens(authorisationServerId, requestParams, codeVerifier, state, nonce) {
|
|
130
|
+
return this.retrieveTokenEndpoint.retrieveTokens(authorisationServerId, requestParams, codeVerifier, state, nonce);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves user information from the UserInfo endpoint.
|
|
134
|
+
*
|
|
135
|
+
* @param authorisationServerId - Authorization server ID
|
|
136
|
+
* @param accessToken - Access token
|
|
137
|
+
* @returns UserInfo claims
|
|
138
|
+
*/
|
|
139
|
+
async getUserInfo(authorisationServerId, accessToken) {
|
|
140
|
+
return this.userInfoEndpoint.getUserInfo(authorisationServerId, accessToken);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Gets the current date (for testing purposes).
|
|
144
|
+
*
|
|
145
|
+
* @returns Current date
|
|
146
|
+
*/
|
|
147
|
+
getCurrentDate() {
|
|
148
|
+
return new Date();
|
|
149
|
+
}
|
|
150
|
+
}
|