Skip to content

Commit 3998cc8

Browse files
authored
Merge pull request #175 from thivi/master
Add multi-user capability to the SDK
2 parents e954131 + 584d645 commit 3998cc8

File tree

6 files changed

+295
-214
lines changed

6 files changed

+295
-214
lines changed

README.md

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ const dataLayer = auth.getDataLayer();
309309
### getAuthorizationURL
310310

311311
```TypeScript
312-
getAuthorizationURL(config?: GetAuthURLConfig): Promise<string>
312+
getAuthorizationURL(config?: GetAuthURLConfig, userID?: string): Promise<string>
313313
```
314314

315315
#### Arguments
@@ -319,7 +319,9 @@ getAuthorizationURL(config?: GetAuthURLConfig): Promise<string>
319319
An optional config object that has the necessary attributes to configure this method. The `forceInit` attribute can be set to `true` to trigger a request to the `.well-known` endpoint and obtain the OIDC endpoints. By default, a request to the `.well-known` endpoint will be sent only if a request to it had not been sent before. If you wish to force a request to the endpoint, you can use this attribute.
320320

321321
The object can only contain key-value pairs that you wish to append as path parameters to the authorization URL. For example, to set the `fidp` parameter, you can insert `fidp` as a key and its value to this object.
322+
2. userID: `string` (optional)
322323

324+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here to generate an authorization URL specific to that user. This can be useful when this SDK is used in backend applications.
323325
#### Returns
324326

325327
A Promise that resolves with the authorization URL
@@ -348,7 +350,7 @@ auth.getAuthorizationURL(config).then((url)=>{
348350
### requestAccessToken
349351

350352
```TypeScript
351-
requestAccessToken(authorizationCode: string, sessionState: string): Promise<TokenResponse>
353+
requestAccessToken(authorizationCode: string, sessionState: string, userID?: string): Promise<TokenResponse>
352354
```
353355

354356
#### Arguments
@@ -360,6 +362,9 @@ requestAccessToken(authorizationCode: string, sessionState: string): Promise<Tok
360362
2. sessionState: `string`
361363

362364
This is the session state obtained from Asgardeo after a user signs in.
365+
3. userID: `string` (optional)
366+
367+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here to request an access token specific to that user. This can be useful when this SDK is used in backend applications.
363368

364369
#### Returns
365370

@@ -386,9 +391,13 @@ auth.requestAccessToken("auth-code", "session-state").then((tokenResponse)=>{
386391
### signOut
387392

388393
```TypeScript
389-
signOut(): Promise<string>
394+
signOut(userID?: string): Promise<string>
390395
```
391396

397+
#### Argument
398+
1. userID: `string` (optional)
399+
400+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
392401
#### Returns
393402

394403
signOutURL: `Promise<string>`
@@ -411,9 +420,12 @@ const signOutURL = await auth.signOut();
411420
### getSignOutURL
412421

413422
```TypeScript
414-
getSignOutURL(): Promise<string>
423+
getSignOutURL(userID?: string): Promise<string>
415424
```
425+
#### Argument
426+
1. userID: `string` (optional)
416427

428+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
417429
#### Returns
418430

419431
signOutURL: `Promise<string>`
@@ -461,9 +473,13 @@ const oidcEndpoints = await auth.getOIDCServiceEndpoints();
461473
### getDecodedIDToken
462474

463475
```TypeScript
464-
getDecodedIDToken(): Promise<DecodedIDTokenPayload>
476+
getDecodedIDToken(userID?: string): Promise<DecodedIDTokenPayload>
465477
```
466478

479+
#### Argument
480+
1. userID: `string` (optional)
481+
482+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
467483
#### Returns
468484

469485
decodedIDTokenPayload: `Promise<[DecodedIDTokenPayload](#DecodedIDTokenPayload)>`
@@ -484,9 +500,14 @@ const decodedIDTokenPayload = await auth.getDecodedIDToken();
484500
### getIDToken
485501

486502
```TypeScript
487-
getIDToken(): Promise<string>
503+
getIDToken(userID?: string): Promise<string>
488504
```
489505

506+
#### Argument
507+
508+
1. userID: `string` (optional)
509+
510+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
490511
#### Returns
491512

492513
idToken: `Promise<string>`
@@ -507,9 +528,13 @@ const idToken = await auth.getIDToken();
507528
### getBasicUserInfo
508529

509530
```TypeScript
510-
getBasicUserInfo(): Promise<BasicUserInfo>
531+
getBasicUserInfo(userID?: string): Promise<BasicUserInfo>
511532
```
512533

534+
#### Argument
535+
1. userID: `string` (optional)
536+
537+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
513538
#### Returns
514539

515540
basicUserInfo: `Promise<[BasicUserInfo](#BasicUserInfo)>`
@@ -531,9 +556,14 @@ const basicUserInfo = await auth.getBasicUserInfo();
531556
### revokeAccessToken
532557

533558
```TypeScript
534-
revokeAccessToken(): Promise<AxiosResponse>
559+
revokeAccessToken(userID?: string): Promise<AxiosResponse>
535560
```
536561

562+
#### Argument
563+
564+
1. userID: `string` (optional)
565+
566+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
537567
#### Returns
538568

539569
A Promise that resolves with the response returned by the server.
@@ -557,9 +587,12 @@ auth.revokeAccessToken().then((response)=>{
557587
### refreshAccessToken
558588

559589
```TypeScript
560-
refreshAccessToken(): Promise<TokenResponse>
590+
refreshAccessToken(userID?: string): Promise<TokenResponse>
561591
```
592+
#### Argument
593+
1. userID: `string` (optional)
562594

595+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
563596
#### Returns
564597

565598
A Promise that resolves with the token response that contains the token information.
@@ -583,9 +616,12 @@ auth.refreshAccessToken().then((response)=>{
583616
### getAccessToken
584617

585618
```TypeScript
586-
getAccessToken(): Promise<string>
619+
getAccessToken(userID?: string): Promise<string>
587620
```
621+
#### Argument
622+
1. userID: `string` (optional)
588623

624+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
589625
#### Returns
590626

591627
accessToken: `string`
@@ -607,14 +643,16 @@ const accessToken = await auth.getAccessToken();
607643
### requestCustomGrant
608644

609645
```TypeScript
610-
requestCustomGrant(config: CustomGrantConfig): Promise<TokenResponse | AxiosResponse>
646+
requestCustomGrant(config: CustomGrantConfig, userID?: string): Promise<TokenResponse | AxiosResponse>
611647
```
612648

613649
#### Arguments
614650

615651
1. config: [`CustomGrantConfig`](#CustomGrantConfig)
616652
The config object contains attributes that would be used to configure the custom grant request. To learn more about the different configurations available, checkout the [`CustomGrantConfig`](#CustomGrantConfig) model.
653+
2. userID: `string` (optional)
617654

655+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
618656
#### Returns
619657

620658
A Promise that resolves with the token information or the response returned by the server depending on the configuration passed.
@@ -652,9 +690,12 @@ This method can be used to send custom-grant requests to Asgardeo.
652690
### isAuthenticated
653691

654692
```TypeScript
655-
isAuthenticated(): Promise<boolean>
693+
isAuthenticated(userID?: string): Promise<boolean>
656694
```
695+
#### Argument
696+
1. userID: `string` (optional)
657697

698+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
658699
#### Returns
659700

660701
isAuth: `boolean`
@@ -676,9 +717,12 @@ const isAuth = await auth.isAuthenticated();
676717
### getPKCECode
677718

678719
```TypeScript
679-
getPKCECode(): string
720+
getPKCECode(userID?: string): string
680721
```
722+
#### Argument
723+
1. userID: `string` (optional)
681724

725+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
682726
#### Returns
683727

684728
pkce: `string`
@@ -700,15 +744,17 @@ const pkce = auth.getPKCECode();
700744
### setPKCECode
701745

702746
```TypeScript
703-
setPKCECode(pkce: string): void
747+
setPKCECode(pkce: string, userID?: string): void
704748
```
705749

706750
#### Arguments
707751

708752
1. pkce: `string`
709753

710754
The PKCE code generated by the [`getAuthorizationURL`](#getAuthorizationURL) method.
755+
2. userID: `string` (optional)
711756

757+
If you want to use the SDK to manage multiple user sessions, you can pass a unique ID here. This can be useful when this SDK is used in backend applications.
712758
#### Description
713759

714760
This method sets the PKCE code to the store. The PKCE code is usually stored in the store by the SDK. But there could be instances when the store could be cleared such as when the data is stored in the memory and the user is redirected to the authorization endpoint in a Single Page Application. When the user is redirected back to the app, the authorization code, session state, and the PKCE code will have to be sent to the server to obtain the access token. However, since, during redirection, everything in the memory is cleared, the PKCE code cannot be obtained. In such instances, the [`getPKCECode`](#getPKCECode) method can be used to get the PKCE code before redirection and store it in a place from where it can be retrieved after redirection, and then this method can be used to save the PKCE code to the store so that the [`requestAccessToken`](#requestAccessToken) method can run successfully.

0 commit comments

Comments
 (0)