@asgardeo/node 0.0.1 → 0.0.3

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 CHANGED
@@ -28,7 +28,7 @@ import { AsgardeoNodeClient } from "@asgardeo/node";
28
28
 
29
29
  // Initialize the client
30
30
  const authClient = new AsgardeoNodeClient({
31
- clientID: "<your_client_id>",
31
+ clientId: "<your_client_id>",
32
32
  clientSecret: "<your_client_secret>",
33
33
  baseUrl: "https://api.asgardeo.io/t/<org_name>",
34
34
  callbackURL: "http://localhost:3000/callback"
@@ -40,7 +40,7 @@ const app = express();
40
40
 
41
41
  // Login endpoint
42
42
  app.get("/login", (req, res) => {
43
- const authUrl = authClient.getAuthorizationURL();
43
+ const authUrl = authClient.getSignInUrl();
44
44
  res.redirect(authUrl);
45
45
  });
46
46
 
@@ -20,7 +20,7 @@ import { AsgardeoNodeConfig } from './models/config';
20
20
  /**
21
21
  * Base class for implementing Asgardeo in Node.js based applications.
22
22
  * This class provides the core functionality for managing user authentication and sessions.
23
- *
23
+ *getConfigData
24
24
  * @typeParam T - Configuration type that extends AsgardeoNodeConfig.
25
25
  */
26
26
  declare abstract class AsgardeoNodeClient<T = AsgardeoNodeConfig> extends AsgardeoJavaScriptClient<T> {
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.
2
+ * Copyright (c) {{year}}, WSO2 LLC. (https://www.wso2.com).
3
3
  *
4
- * WSO2 Inc. licenses this file to you under the Apache License,
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
5
  * Version 2.0 (the "License"); you may not use this file except
6
6
  * in compliance with the License.
7
7
  * You may obtain a copy of the License at
@@ -15,7 +15,7 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- import { AuthClientConfig, BasicUserInfo, CustomGrantConfig, DataLayer, IdTokenPayload, FetchResponse, OIDCEndpoints, Store, TokenResponse } from '@asgardeo/javascript';
18
+ import { AuthClientConfig, TokenExchangeRequestConfig, StorageManager, IdToken, OIDCEndpoints, Storage, TokenResponse, User, ExtendedAuthorizeRequestUrlParams } from '@asgardeo/javascript';
19
19
  import { AuthURLCallback } from './models';
20
20
  /**
21
21
  * This class provides the necessary methods needed to implement authentication.
@@ -29,15 +29,15 @@ export declare class AsgardeoNodeClient<T> {
29
29
  * This is the constructor method that returns an instance of the `AsgardeoNodeClient` class.
30
30
  *
31
31
  * @param {AuthClientConfig<T>} config - The configuration object.
32
- * @param {Store} store - The store object.
32
+ * @param {Storage} store - The store object.
33
33
  *
34
34
  * @example
35
35
  * ```
36
- * const _store: Store = new DataStore();
36
+ * const _store: Storage = new DataStore();
37
37
  * const _config = {
38
- signInRedirectURL: "http://localhost:3000/sign-in",
39
- signOutRedirectURL: "http://localhost:3000/dashboard",
40
- clientID: "client ID",
38
+ afterSignInUrl: "http://localhost:3000/sign-in",
39
+ afterSignOutUrl: "http://localhost:3000/dashboard",
40
+ clientId: "client ID",
41
41
  serverOrigin: "https://api.asgardeo.io/t/<org_name>"
42
42
  };
43
43
  * const auth = new AsgardeoNodeClient(_config,_store);
@@ -47,13 +47,13 @@ export declare class AsgardeoNodeClient<T> {
47
47
  * @preserve
48
48
  */
49
49
  constructor();
50
- initialize(config: AuthClientConfig<T>, store?: Store): Promise<boolean>;
50
+ initialize(config: AuthClientConfig<T>, store?: Storage): Promise<boolean>;
51
51
  /**
52
52
  * This method logs in a user. If the authorization code is not available it will resolve with the
53
53
  * authorization URL to authorize the user.
54
54
  * @param {string} authorizationCode - The authorization code obtained from Asgardeo after a user signs in.
55
55
  * @param {String} sessionState - The session state obtained from Asgardeo after a user signs in.
56
- * @param {string} userID - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
56
+ * @param {string} userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
57
57
  * scenarios where each user should be uniquely identified.
58
58
  * @param {string} state - The state parameter in the redirect URL.
59
59
  *
@@ -81,6 +81,12 @@ export declare class AsgardeoNodeClient<T> {
81
81
  *
82
82
  */
83
83
  signIn(authURLCallback: AuthURLCallback, userId: string, authorizationCode?: string, sessionState?: string, state?: string, signInConfig?: Record<string, string | boolean>): Promise<TokenResponse>;
84
+ /**
85
+ * Method to get the configuration data.
86
+ *
87
+ * @returns {Promise<AuthClientConfig<Config>>} - A promise that resolves with the configuration data.
88
+ */
89
+ getConfigData(): Promise<AuthClientConfig<T>>;
84
90
  /**
85
91
  * This method clears all session data and returns the sign-out URL.
86
92
  * @param {string} userId - The userId of the user. (If you are using ExpressJS,
@@ -108,15 +114,15 @@ export declare class AsgardeoNodeClient<T> {
108
114
  *
109
115
  * @example
110
116
  * ```
111
- * const isAuth = await authClient.isAuthenticated("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
117
+ * const isAuth = await authClient.isSignedIn("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
112
118
  * ```
113
119
  *
114
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isAuthenticated
120
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignedIn
115
121
  *
116
122
  * @memberof AsgardeoNodeClient
117
123
  *
118
124
  */
119
- isAuthenticated(userId: string): Promise<boolean>;
125
+ isSignedIn(userId: string): Promise<boolean>;
120
126
  /**
121
127
  * This method returns the id token.
122
128
  * @param {string} userId - The userId of the user.
@@ -126,15 +132,15 @@ export declare class AsgardeoNodeClient<T> {
126
132
  *
127
133
  * @example
128
134
  * ```
129
- * const isAuth = await authClient.getIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
135
+ * const isAuth = await authClient.getIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
130
136
  * ```
131
137
  *
132
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIDToken
138
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIdToken
133
139
  *
134
140
  * @memberof AsgardeoNodeClient
135
141
  *
136
142
  */
137
- getIDToken(userId: string): Promise<string>;
143
+ getIdToken(userId: string): Promise<string>;
138
144
  /**
139
145
  * This method returns an object containing basic user information obtained from the id token.
140
146
  * @param {string} userId - The userId of the user.
@@ -145,15 +151,15 @@ export declare class AsgardeoNodeClient<T> {
145
151
  *
146
152
  * @example
147
153
  * ```
148
- * const basicInfo = await authClient.getBasicUserInfo("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
154
+ * const basicInfo = await authClient.getUser("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
149
155
  * ```
150
156
  *
151
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getBasicUserInfo
157
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getUser
152
158
  *
153
159
  * @memberof AsgardeoNodeClient
154
160
  *
155
161
  */
156
- getBasicUserInfo(userId: string): Promise<BasicUserInfo>;
162
+ getUser(userId: string): Promise<User>;
157
163
  /**
158
164
  * This method returns an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
159
165
  * @return {Promise<OIDCEndpoints>} -A Promise that resolves with
@@ -161,34 +167,34 @@ export declare class AsgardeoNodeClient<T> {
161
167
  *
162
168
  * @example
163
169
  * ```
164
- * const oidcEndpoints = await auth.getOIDCServiceEndpoints();
170
+ * const oidcEndpoints = await auth.getOpenIDProviderEndpoints();
165
171
  * ```
166
172
  *
167
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOIDCServiceEndpoints
173
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOpenIDProviderEndpoints
168
174
  *
169
175
  * @memberof AsgardeoNodeClient
170
176
  *
171
177
  */
172
- getOIDCServiceEndpoints(): Promise<OIDCEndpoints>;
178
+ getOpenIDProviderEndpoints(): Promise<OIDCEndpoints>;
173
179
  /**
174
180
  * This method returns the decoded ID token payload.
175
181
  * @param {string} userId - The userId of the user.
176
182
  * (If you are using ExpressJS, you may get this from the request cookies)
177
183
  *
178
- * @return {Promise<IdTokenPayload>} -A Promise that resolves with
184
+ * @return {Promise<IdToken>} -A Promise that resolves with
179
185
  * an object containing the decoded ID token payload.
180
186
  *
181
187
  * @example
182
188
  * ```
183
- * const decodedIDTokenPayload = await auth.getDecodedIDToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
189
+ * const decodedIDTokenPayload = await auth.getDecodedIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
184
190
  * ```
185
191
  *
186
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIDToken
192
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIdToken
187
193
  *
188
194
  * @memberof AsgardeoNodeClient
189
195
  *
190
196
  */
191
- getDecodedIDToken(userId?: string): Promise<IdTokenPayload>;
197
+ getDecodedIdToken(userId?: string): Promise<IdToken>;
192
198
  /**
193
199
  * This method returns the access token.
194
200
  * @param {string} userId - The userId of the user.
@@ -211,13 +217,13 @@ export declare class AsgardeoNodeClient<T> {
211
217
  /**
212
218
  * This method returns Promise that resolves with the token information
213
219
  * or the response returned by the server depending on the configuration passed.
214
- * @param {CustomGrantConfig} config - The config object contains attributes that would be used
220
+ * @param {TokenExchangeRequestConfig} config - The config object contains attributes that would be used
215
221
  * to configure the custom grant request.
216
222
  *
217
223
  * @param {string} userId - The userId of the user.
218
224
  * (If you are using ExpressJS, you may get this from the request cookies)
219
225
  *
220
- * @return {Promise<TokenResponse | FetchResponse>} -A Promise that resolves with the token information
226
+ * @return {Promise<TokenResponse | Response>} -A Promise that resolves with the token information
221
227
  * or the response returned by the server depending on the configuration passed.
222
228
  *
223
229
  * @example
@@ -225,7 +231,7 @@ export declare class AsgardeoNodeClient<T> {
225
231
  * const config = {
226
232
  * attachToken: false,
227
233
  * data: {
228
- * client_id: "{{clientID}}",
234
+ * client_id: "{{clientId}}",
229
235
  * grant_type: "account_switch",
230
236
  * scope: "{{scope}}",
231
237
  * token: "{{token}}",
@@ -236,19 +242,19 @@ export declare class AsgardeoNodeClient<T> {
236
242
  * signInRequired: true
237
243
  * }
238
244
 
239
- * auth.requestCustomGrant(config).then((response)=>{
245
+ * auth.exchangeToken(config).then((response)=>{
240
246
  * console.log(response);
241
247
  * }).catch((error)=>{
242
248
  * console.error(error);
243
249
  * });
244
250
  * ```
245
251
  *
246
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#requestCustomGrant
252
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#exchangeToken
247
253
  *
248
254
  * @memberof AsgardeoNodeClient
249
255
  *
250
256
  */
251
- requestCustomGrant(config: CustomGrantConfig, userId?: string): Promise<TokenResponse | FetchResponse>;
257
+ exchangeToken(config: TokenExchangeRequestConfig, userId?: string): Promise<TokenResponse | Response>;
252
258
  /**
253
259
  * This method can be used to update the configurations passed into the constructor of the AsgardeoAuthClient.
254
260
  * @param {AuthClientConfig<T>} config - The config object containing the attributes
@@ -258,23 +264,24 @@ export declare class AsgardeoNodeClient<T> {
258
264
  *
259
265
  * @example
260
266
  * ```
261
- * const updateConfig = await auth.updateConfig({
262
- * signOutRedirectURL: "http://localhost:3000/sign-out"
267
+ * const reInitialize = await auth.reInitialize({
268
+ * afterSignOutUrl: "http://localhost:3000/sign-out"
263
269
  * });
264
270
  * ```
265
271
  *
266
- * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#updateConfig
272
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#reInitialize
267
273
  *
268
274
  * @memberof AsgardeoNodeClient
269
275
  *
270
276
  */
271
- updateConfig(config: Partial<AuthClientConfig<T>>): Promise<void>;
277
+ reInitialize(config: Partial<AuthClientConfig<T>>): Promise<void>;
278
+ getSignInUrl(requestConfig?: ExtendedAuthorizeRequestUrlParams, userId?: string): Promise<string>;
272
279
  /**
273
280
  * This method returns a Promise that resolves with the response returned by the server.
274
281
  * @param {string} userId - The userId of the user.
275
282
  * (If you are using ExpressJS, you may get this from the request cookies)
276
283
  *
277
- * @return {Promise<FetchResponse>} -A Promise that resolves with the response returned by the server.
284
+ * @return {Promise<Response>} -A Promise that resolves with the response returned by the server.
278
285
  *
279
286
  * @example
280
287
  * ```
@@ -286,7 +293,7 @@ export declare class AsgardeoNodeClient<T> {
286
293
  * @memberof AsgardeoNodeClient
287
294
  *
288
295
  */
289
- revokeAccessToken(userId?: string): Promise<FetchResponse>;
296
+ revokeAccessToken(userId?: string): Promise<Response>;
290
297
  /**
291
298
  * This method refreshes the access token and returns a Promise that resolves with the new access
292
299
  * token and other relevant data.
@@ -308,7 +315,7 @@ export declare class AsgardeoNodeClient<T> {
308
315
  refreshAccessToken(userId?: string): Promise<TokenResponse>;
309
316
  /**
310
317
  * This method returns if the user has been successfully signed out or not.
311
- * @param {string} signOutRedirectURL - The URL to which the user is redirected to
318
+ * @param {string} afterSignOutUrl - The URL to which the user is redirected to
312
319
  * after signing out from the server.
313
320
  *
314
321
  * @return {boolean} - A boolean value indicating if the user has been signed out or not.
@@ -323,10 +330,10 @@ export declare class AsgardeoNodeClient<T> {
323
330
  * @memberof AsgardeoNodeClient
324
331
  *
325
332
  */
326
- static isSignOutSuccessful(signOutRedirectURL: string): boolean;
333
+ static isSignOutSuccessful(afterSignOutUrl: string): boolean;
327
334
  /**
328
335
  * This method returns if sign-out failed or not
329
- * @param {string} signOutRedirectURL - The URL to which the user is redirected to
336
+ * @param {string} afterSignOutUrl - The URL to which the user is redirected to
330
337
  * after signing out from the server.
331
338
  *
332
339
  * @return {boolean} - A boolean value indicating if sign-out failed or not.
@@ -341,6 +348,6 @@ export declare class AsgardeoNodeClient<T> {
341
348
  * @memberof AsgardeoNodeClient
342
349
  *
343
350
  */
344
- static didSignOutFail(signOutRedirectURL: string): boolean;
345
- getDataLayer(): Promise<DataLayer<T>>;
351
+ static didSignOutFail(afterSignOutUrl: string): boolean;
352
+ getStorageManager(): Promise<StorageManager<T>>;
346
353
  }
@@ -15,29 +15,30 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- import { AuthClientConfig, BasicUserInfo, CustomGrantConfig, DataLayer, IdTokenPayload, FetchResponse, OIDCEndpoints, Store, TokenResponse } from '@asgardeo/javascript';
18
+ import { AuthClientConfig, TokenExchangeRequestConfig, StorageManager, IdToken, OIDCEndpoints, Storage, TokenResponse, User } from '@asgardeo/javascript';
19
19
  import { AuthURLCallback } from '../models';
20
20
  export declare class AsgardeoNodeCore<T> {
21
21
  private _auth;
22
22
  private _cryptoUtils;
23
23
  private _store;
24
- private _dataLayer;
25
- constructor(config: AuthClientConfig<T>, store?: Store);
26
- signIn(authURLCallback: AuthURLCallback, userID: string, authorizationCode?: string, sessionState?: string, state?: string, signInConfig?: Record<string, string | boolean>): Promise<TokenResponse>;
24
+ private _storageManager;
25
+ constructor(config: AuthClientConfig<T>, store?: Storage);
26
+ signIn(authURLCallback: AuthURLCallback, userId: string, authorizationCode?: string, sessionState?: string, state?: string, signInConfig?: Record<string, string | boolean>): Promise<TokenResponse>;
27
27
  getAuthURL(userId: string, signInConfig?: Record<string, string | boolean>): Promise<string>;
28
28
  requestAccessToken(authorizationCode: string, sessionState: string, userId: string, state: string): Promise<TokenResponse>;
29
- getIDToken(userId: string): Promise<string>;
29
+ getIdToken(userId: string): Promise<string>;
30
30
  refreshAccessToken(userId?: string): Promise<TokenResponse>;
31
- isAuthenticated(userId: string): Promise<boolean>;
31
+ isSignedIn(userId: string): Promise<boolean>;
32
32
  signOut(userId: string): Promise<string>;
33
- getBasicUserInfo(userId: string): Promise<BasicUserInfo>;
34
- getOIDCServiceEndpoints(): Promise<OIDCEndpoints>;
35
- getDecodedIDToken(userId?: string): Promise<IdTokenPayload>;
33
+ getUser(userId: string): Promise<User>;
34
+ getConfigData(): Promise<AuthClientConfig<T>>;
35
+ getOpenIDProviderEndpoints(): Promise<OIDCEndpoints>;
36
+ getDecodedIdToken(userId?: string): Promise<IdToken>;
36
37
  getAccessToken(userId?: string): Promise<string>;
37
- requestCustomGrant(config: CustomGrantConfig, userId?: string): Promise<TokenResponse | FetchResponse>;
38
- updateConfig(config: Partial<AuthClientConfig<T>>): Promise<void>;
39
- revokeAccessToken(userId?: string): Promise<FetchResponse>;
40
- static didSignOutFail(signOutRedirectURL: string): boolean;
41
- static isSignOutSuccessful(signOutRedirectURL: string): boolean;
42
- getDataLayer(): DataLayer<T>;
38
+ exchangeToken(config: TokenExchangeRequestConfig, userId?: string): Promise<TokenResponse | Response>;
39
+ reInitialize(config: Partial<AuthClientConfig<T>>): Promise<void>;
40
+ revokeAccessToken(userId?: string): Promise<Response>;
41
+ static didSignOutFail(afterSignOutUrl: string): boolean;
42
+ static isSignOutSuccessful(afterSignOutUrl: string): boolean;
43
+ getStorageManager(): StorageManager<T>;
43
44
  }
@@ -15,8 +15,8 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- import { Store } from '@asgardeo/javascript';
19
- export declare class MemoryCacheStore implements Store {
18
+ import { Storage } from '@asgardeo/javascript';
19
+ export declare class MemoryCacheStore implements Storage {
20
20
  setData(key: string, value: string): Promise<void>;
21
21
  getData(key: string): Promise<string>;
22
22
  removeData(key: string): Promise<void>;
@@ -27,5 +27,5 @@ export declare class NodeCryptoUtils implements Crypto<Buffer | string> {
27
27
  base64URLDecode(value: string): string;
28
28
  hashSha256(data: string): string | Buffer;
29
29
  generateRandomBytes(length: number): string | Buffer;
30
- verifyJwt(idToken: string, jwk: Partial<JWKInterface>, algorithms: string[], clientID: string, issuer: string, subject: string, clockTolerance?: number): Promise<boolean>;
30
+ verifyJwt(idToken: string, jwk: Partial<JWKInterface>, algorithms: string[], clientId: string, issuer: string, subject: string, clockTolerance?: number): Promise<boolean>;
31
31
  }