@scalekit-sdk/node 1.0.3 → 1.0.4
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/.github/dependabot.yml +10 -0
- package/README.md +81 -11
- package/lib/connect.js +5 -4
- package/lib/connect.js.map +1 -1
- package/lib/connection.d.ts +17 -3
- package/lib/connection.js +36 -2
- package/lib/connection.js.map +1 -1
- package/lib/constants/user.d.ts +1 -1
- package/lib/core.d.ts +9 -5
- package/lib/core.js +26 -22
- package/lib/core.js.map +1 -1
- package/lib/domain.d.ts +1 -12
- package/lib/domain.js +0 -19
- package/lib/domain.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/organization.d.ts +22 -4
- package/lib/organization.js +44 -7
- package/lib/organization.js.map +1 -1
- package/lib/scalekit.d.ts +11 -14
- package/lib/scalekit.js +17 -14
- package/lib/scalekit.js.map +1 -1
- package/lib/types/{user.d.ts → auth.d.ts} +5 -0
- package/lib/types/{user.js → auth.js} +1 -1
- package/lib/types/auth.js.map +1 -0
- package/lib/types/scalekit.d.ts +9 -9
- package/lib/types/scalekit.js.map +1 -1
- package/package.json +1 -1
- package/src/connect.ts +5 -5
- package/src/connection.ts +41 -3
- package/src/constants/user.ts +1 -1
- package/src/core.ts +32 -25
- package/src/domain.ts +0 -21
- package/src/index.ts +4 -4
- package/src/organization.ts +52 -5
- package/src/scalekit.ts +26 -17
- package/src/types/{user.ts → auth.ts} +6 -0
- package/src/types/scalekit.ts +11 -11
- package/lib/types/user.js.map +0 -1
package/src/scalekit.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { IdTokenClaimToUserMap } from './constants/user';
|
|
|
6
6
|
import CoreClient from './core';
|
|
7
7
|
import DomainClient from './domain';
|
|
8
8
|
import OrganizationClient from './organization';
|
|
9
|
-
import { AuthorizationUrlOptions,
|
|
10
|
-
import { IdTokenClaim, User } from './types/
|
|
9
|
+
import { AuthorizationUrlOptions, AuthenticationOptions, GrantType, AuthenticationResponse } from './types/scalekit';
|
|
10
|
+
import { IdTokenClaim, User } from './types/auth';
|
|
11
11
|
|
|
12
12
|
const authorizeEndpoint = "oauth/authorize";
|
|
13
13
|
|
|
@@ -16,11 +16,11 @@ const authorizeEndpoint = "oauth/authorize";
|
|
|
16
16
|
* @param {string} envUrl The environment url
|
|
17
17
|
* @param {string} clientId The client id
|
|
18
18
|
* @param {string} clientSecret The client secret
|
|
19
|
-
* @returns {
|
|
19
|
+
* @returns {ScalekitClient} Returns the scalekit instance
|
|
20
20
|
* @example
|
|
21
21
|
* const scalekit = new Scalekit(envUrl, clientId, clientSecret);
|
|
22
22
|
*/
|
|
23
|
-
export default class
|
|
23
|
+
export default class ScalekitClient {
|
|
24
24
|
private readonly coreClient: CoreClient;
|
|
25
25
|
private readonly grpcConnect: GrpcConnect;
|
|
26
26
|
readonly organization: OrganizationClient;
|
|
@@ -65,6 +65,8 @@ export default class Scalekit {
|
|
|
65
65
|
* @param {string} options.domainHint Domain hint parameter
|
|
66
66
|
* @param {string} options.connectionId Connection id parameter
|
|
67
67
|
* @param {string} options.organizationId Organization id parameter
|
|
68
|
+
* @param {string} options.codeChallenge Code challenge parameter in case of PKCE
|
|
69
|
+
* @param {string} options.codeChallengeMethod Code challenge method parameter in case of PKCE
|
|
68
70
|
*
|
|
69
71
|
* @example
|
|
70
72
|
* const scalekit = new Scalekit(envUrl, clientId, clientSecret);
|
|
@@ -76,7 +78,7 @@ export default class Scalekit {
|
|
|
76
78
|
options?: AuthorizationUrlOptions
|
|
77
79
|
): string {
|
|
78
80
|
const defaultOptions: AuthorizationUrlOptions = {
|
|
79
|
-
scopes: ['openid', 'profile']
|
|
81
|
+
scopes: ['openid', 'profile', 'email']
|
|
80
82
|
}
|
|
81
83
|
options = {
|
|
82
84
|
...defaultOptions,
|
|
@@ -94,6 +96,8 @@ export default class Scalekit {
|
|
|
94
96
|
...(options.domainHint && { domain: options.domainHint }),
|
|
95
97
|
...(options.connectionId && { connection_id: options.connectionId }),
|
|
96
98
|
...(options.organizationId && { organization_id: options.organizationId }),
|
|
99
|
+
...(options.codeChallenge && { code_challenge: options.codeChallenge }),
|
|
100
|
+
...(options.codeChallengeMethod && { code_challenge_method: options.codeChallengeMethod })
|
|
97
101
|
})
|
|
98
102
|
|
|
99
103
|
return `${this.coreClient.envUrl}/${authorizeEndpoint}?${qs}`
|
|
@@ -101,24 +105,28 @@ export default class Scalekit {
|
|
|
101
105
|
|
|
102
106
|
/**
|
|
103
107
|
* Authenticate with the code
|
|
104
|
-
* @param {
|
|
105
|
-
* @param {string}
|
|
106
|
-
* @param {
|
|
107
|
-
* @param {string} options.codeVerifier Code verifier
|
|
108
|
-
* @returns {Promise<
|
|
108
|
+
* @param {string} code Code
|
|
109
|
+
* @param {string} redirectUri Redirect uri
|
|
110
|
+
* @param {AuthenticationOptions} options Code authentication options
|
|
111
|
+
* @param {string} options.codeVerifier Code verifier in case of PKCE
|
|
112
|
+
* @returns {Promise<AuthenticationResponse>} Returns user, id token and access token
|
|
109
113
|
*/
|
|
110
|
-
async authenticateWithCode(
|
|
114
|
+
async authenticateWithCode(
|
|
115
|
+
code: string,
|
|
116
|
+
redirectUri: string,
|
|
117
|
+
options?: AuthenticationOptions,
|
|
118
|
+
): Promise<AuthenticationResponse> {
|
|
111
119
|
const res = await this.coreClient.authenticate(QueryString.stringify({
|
|
112
|
-
code:
|
|
113
|
-
redirect_uri:
|
|
120
|
+
code: code,
|
|
121
|
+
redirect_uri: redirectUri,
|
|
114
122
|
grant_type: GrantType.AuthorizationCode,
|
|
115
123
|
client_id: this.coreClient.clientId,
|
|
116
124
|
client_secret: this.coreClient.clientSecret,
|
|
117
|
-
...(options
|
|
125
|
+
...(options?.codeVerifier && { code_verifier: options.codeVerifier })
|
|
118
126
|
}))
|
|
119
|
-
const { id_token, access_token } = res.data;
|
|
127
|
+
const { id_token, access_token, expires_in } = res.data;
|
|
120
128
|
const claims = jose.decodeJwt<IdTokenClaim>(id_token);
|
|
121
|
-
const user
|
|
129
|
+
const user = <User>{};
|
|
122
130
|
for (const [k, v] of Object.entries(claims)) {
|
|
123
131
|
if (IdTokenClaimToUserMap[k]) {
|
|
124
132
|
user[IdTokenClaimToUserMap[k]] = v;
|
|
@@ -128,7 +136,8 @@ export default class Scalekit {
|
|
|
128
136
|
return {
|
|
129
137
|
user,
|
|
130
138
|
idToken: id_token,
|
|
131
|
-
accessToken: access_token
|
|
139
|
+
accessToken: access_token,
|
|
140
|
+
expiresIn: expires_in
|
|
132
141
|
}
|
|
133
142
|
}
|
|
134
143
|
|
package/src/types/scalekit.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { User } from './auth';
|
|
2
|
+
|
|
1
3
|
export enum GrantType {
|
|
2
4
|
AuthorizationCode = 'authorization_code',
|
|
3
5
|
RefreshToken = 'refresh_token',
|
|
@@ -12,19 +14,17 @@ export type AuthorizationUrlOptions = {
|
|
|
12
14
|
nonce?: string;
|
|
13
15
|
domainHint?: string;
|
|
14
16
|
loginHint?: string;
|
|
17
|
+
codeChallenge?: string;
|
|
18
|
+
codeChallengeMethod?: string;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
export type
|
|
18
|
-
|
|
19
|
-
redirectUri: string;
|
|
20
|
-
codeVerifier?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type RefreshTokenAuthenticationOptions = {
|
|
24
|
-
code: string;
|
|
25
|
-
redirectUri: string;
|
|
21
|
+
export type AuthenticationOptions = {
|
|
22
|
+
codeVerifier?: string;
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
export type
|
|
29
|
-
|
|
25
|
+
export type AuthenticationResponse = {
|
|
26
|
+
user: User;
|
|
27
|
+
idToken: string;
|
|
28
|
+
accessToken: string;
|
|
29
|
+
expiresIn: number;
|
|
30
30
|
}
|
package/lib/types/user.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":""}
|