Gathering detailed insights and metrics for @brionmario-experimental/asgardeo-auth-js
Gathering detailed insights and metrics for @brionmario-experimental/asgardeo-auth-js
Gathering detailed insights and metrics for @brionmario-experimental/asgardeo-auth-js
Gathering detailed insights and metrics for @brionmario-experimental/asgardeo-auth-js
OIDC JavaScript SDK for Asgardeo
npm install @brionmario-experimental/asgardeo-auth-js
Typescript
Module System
Node Version
NPM Version
TypeScript (89.66%)
JavaScript (10.34%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
25 Stars
2,097 Commits
43 Forks
33 Watchers
18 Branches
35 Contributors
Updated on Apr 29, 2025
Latest Version
5.2.8
Package Id
@brionmario-experimental/asgardeo-auth-js@5.2.8
Unpacked Size
830.77 kB
Size
145.31 kB
File Count
178
NPM Version
10.8.2
Node Version
18.20.7
Published on
Mar 26, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
14
⚠️ This is a core SDK that is not supposed to be used in applications.
If you are looking for an SDK to use in your application, then you can find the relevant information in the table below:
Framework/Library | Link |
---|---|
React | https://github.com/asgardeo/asgardeo-auth-react-sdk |
Vanilla JavaScript / jQuery / any other frontend frameworks/libraries | https://github.com/asgardeo/asgardeo-auth-spa-sdk |
Node.js | https://github.com/asgardeo/asgardeo-auth-node-sdk |
Express.js | https://github.com/asgardeo/asgardeo-auth-express-sdk |
Asgardeo Auth JavaScript SDK provides the core methods that are needed to implement OIDC authentication in JavaScript/TypeScript-based apps. This SDK can be used to build SDKs for Single-Page Applications, React Native, Node.JS and various other frameworks that use JavaScript.
Create an organization in Asgardeo if you don't already have one. The organization name you choose will be referred to as <org_name>
throughout this tutorial.
Install the library from the npm registry.
npm install @asgardeo/auth-js
1// The SDK provides a client that can be used to carry out the authentication. 2import { AsgardeoAuthClient } from "@asgardeo/auth-js"; 3 4// Create a config object containing the necessary configurations. 5const config = { 6 signInRedirectURL: "http://localhost:3000/sign-in", 7 signOutRedirectURL: "http://localhost:3000/dashboard", 8 clientID: "client ID", 9 baseUrl: "https://api.asgardeo.io/t/<org_name>" 10}; 11 12// Create a Store class to store the authentication data. The following implementation uses the session storage. 13class SessionStore { 14 // Saves the data to the store. 15 async setData(key, value) { 16 sessionStorage.setItem(key, value); 17 } 18 19 // Gets the data from the store. 20 async getData(key) { 21 return sessionStorage.getItem(key); 22 } 23 24 // Removes the date from the store. 25 async removeData(key) { 26 sessionStorage.removeItem(key); 27 } 28} 29 30class CryptoUtils { 31 // Encodes the input data into base64 URL encoded string. 32 public base64URLEncode(value) { 33 return base64url.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""); 34 } 35 36 // Decodes the base64 URL encoded string into the original data. 37 public base64URLDecode(value) { 38 return base64url.decode(value).toString(); 39 } 40 41 // Hashes the input data using SHA256. 42 public hashSha256(data) { 43 return Buffer.from(sha256(new TextEncoder().encode(data))); 44 } 45 46 // Generates a random bytes of the specified length. 47 public generateRandomBytes(length) { 48 return randombytes(length); 49 } 50 51 // Verifies the JWT signature. 52 public verifyJwt( 53 idToken, 54 jwk, 55 algorithms, 56 clientID, 57 issuer, 58 subject, 59 clockTolerance 60 ) { 61 // Parses the key object into a format that would be accepted by verifyJwt() 62 const key = parseJwk(jwk); 63 64 return jwtVerify(idToken, jwk, { 65 algorithms: algorithms, 66 audience: clientID, 67 clockTolerance: clockTolerance, 68 issuer: issuer, 69 subject: subject 70 }).then(() => { 71 return Promise.resolve(true); 72 }); 73 } 74} 75 76// Instantiate the SessionStore class 77const store = new SessionStore(); 78 79// Instantiate the CryptoUtils class 80const cryptoUtils = new CryptoUtils(); 81 82// Instantiate the AsgardeoAuthClient and pass the store object as an argument into the constructor. 83const auth = new AsgardeoAuthClient(); 84 85// Initialize the instance with the config object. 86auth.initialize(config, store, cryptoUtils); 87 88// To get the authorization URL, simply call this method. 89auth.getAuthorizationURL() 90 .then((url) => { 91 // Redirect the user to the authentication URL. If this is used in a browser, 92 // you may want to do something like this: 93 window.location.href = url; 94 }) 95 .catch((error) => { 96 console.error(error); 97 }); 98 99// Once you obtain the authentication code and the session state from the server, you can use this method 100// to get the access token. 101auth.requestAccessToken("code", "session-state", "state") 102 .then((response) => { 103 // Obtain the token and other related from the response; 104 console.log(response); 105 }) 106 .catch((error) => { 107 console.error(error); 108 });
The SDK provides a client class called AsgardeoAuthClient
that provides you with the necessary methods to implement authentication.
You can instantiate the class and use the object to access the provided methods.
1new AsgardeoAuthClient();
This creates an instance of the AsgardeoAuthClient
class and returns it.
1const auth = new AsgardeoAuthClient();
1initialize(config: AuthClientConfig<T>, store: Store, cryptoUtils: CryptoUtils): Promise<void>;
config: AuthClientConfig<T>
This contains the configuration information needed to implement authentication such as the client ID, server origin etc. Additional configuration information that is needed to be stored can be passed by extending the type of this argument using the generic type parameter. For example, if you want the config to have an attribute called foo
, you can create an interface called Bar
in TypeScript and then pass that interface as the generic type to AuthClientConfig
interface. To learn more about what attributes can be passed into this object, refer to the AuthClientConfig<T>
section.
1interface Bar {
2 foo: string
3}
4
5const auth = new AsgardeoAuthClient(config: AuthClientConfig<Bar>, store: Store, cryptoUtils: CryptoUtils);
store: Store
This is the object of interface Store
that is used by the SDK to store all the necessary data used ranging from the configuration data to the access token. You can implement the Store to create a class with your own implementation logic and pass an instance of the class as the second argument. This way, you will be able to get the data stored in your preferred place. To know more about implementing the Store
interface, refer to the Data Storage section.
cryptoUtils: CryptoUtils
This is the object of the interface CryptoUtils
that is used by the SDK to perform cryptographic functions. Since the crypto implementation varies from environment to environment, this object is used to inject environment-specific crypto implementation. So, developers are expected to implement this interface and pass an object of this interface as an argument to the constructor. To know more about implementing this interface, refer to the CryptoUtils
section.
This method initializes the instance with the config data.
1const config = { 2 signInRedirectURL: "http://localhost:3000/sign-in", 3 signOutRedirectURL: "http://localhost:3000/dashboard", 4 clientID: "client ID", 5 baseUrl: "https://api.asgardeo.io/t/<org_name>" 6}; 7const _store: Store = initiateStore(config.storage); 8const _cryptoUtils: SPACryptoUtils = new SPACryptoUtils(); 9 10const auth = new AsgardeoAuthClient<MainThreadClientConfig>(); 11 12await auth.initialize(config, _store, _cryptoUtils);
1getDataLayer(): DataLayer<T>
dataLayer : DataLayer
A DataLayer
object wraps the Store
object passed during object instantiation and provides access to various types of data used by the SDK. To learn more about the various types of interfaces provide by the DataLayer
, refer to the Data layer section.
This method returns the DataLayer
object used by the SDK to store authentication data.
1const dataLayer = auth.getDataLayer();
1getCryptoHelper(): Promise<CryptoHelper>
cryptoHelper : CryptoHelper
A CryptoHelper
provides support for performing a cryptographic operation such as producing a PKCE code and verifying ID tokens. To learn more about the various types of interfaces provided by the CryptoHelper
, refer to the Crypto Utils section.
This method returns the CryptoHelper
object used by the SDK to perform cryptographic operations.
1const cryptoHelper = auth.getCryptoHelper();
1getAuthorizationURLParams(config?: GetAuthURLConfig, userID?: string): Promise<Map<string, string>>
config: GetAuthURLConfig
(optional)
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.
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.
userID: string
(optional)
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.
A Promise that resolves with the authorization URL Parameters.
This method returns a Promise that resolves with the authorization URL Parameters, which then can be used to build the authorization request.
1const config = { 2 forceInit: true, 3 fidp: "fb" 4} 5 6auth.getAuthorizationURLParams(config).then((params)=>{ 7 console.log(params); 8}).catch((error)=>{ 9 console.error(error); 10});
1getAuthorizationURL(config?: GetAuthURLConfig, userID?: string): Promise<string>
config: GetAuthURLConfig
(optional)
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.
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.
userID: string
(optional)
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.
A Promise that resolves with the authorization URL
This method returns a Promise that resolves with the authorization URL. The user can be redirected to this URL to authenticate themselves and authorize the client.
1const config = { 2 forceInit: true, 3 fidp: "fb" 4} 5 6auth.getAuthorizationURL(config).then((url)=>{ 7 window.location.href = url; 8}).catch((error)=>{ 9 console.error(error); 10});
1requestAccessToken(authorizationCode: string, sessionState: string, state: string, userID?: string, tokenRequestConfig: { params: Record<string, unknown> }): Promise<TokenResponse>
authorizationCode: string
This is the authorization code obtained from Asgardeo after a user signs in.
sessionState: string
This is the session state obtained from Asgardeo after a user signs in.
state: string
This is the the state parameter passed in the authorization URL.
userID: string
(optional)
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.
tokenRequestConfig: object
(optional)
An optional configuration object that allows you to augment the token request.
params
(Mandatory): Key-value pairs to be sent as additional parameters in the token request payload.
1tokenRequestConfig: { 2 params: Record<string, unknown> 3}
A Promise that resolves with the TokenResponse
object.
The object contains data returned by the token response such as the access token, id token, refresh token, etc. You can learn more about the data returned from the TokenResponse
section.
This method uses the authorization code and the session state that are passed as arguments to send a request to the token
endpoint to obtain the access token and the id token. The sign-in functionality can be implemented by calling the getAuthorizationURL
method followed by this method.
1auth.requestAccessToken("auth-code", "session-state", "request_0").then((tokenResponse)=>{ 2 console.log(tokenResponse); 3}).catch((error)=>{ 4 console.error(error); 5});
1getSignOutURL(userID?: string): Promise<string>
userID: string
(optional)
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.
signOutURL: Promise<string>
The user should be redirected to this URL in order to sign out of the server.
This method returns the sign-out URL to which the user should be redirected to be signed out from the server.
1// This should be within an async function. 2const signOutURL = await auth.getSignOutURL();
1getOIDCServiceEndpoints(): Promise<OIDCEndpoints>
oidcEndpoints: Promise<[OIDCEndpoints](#OIDCEndpoints)>
An object containing the OIDC service endpoints returned by the .well-known
endpoint.
This method returns the OIDC service endpoints obtained from the .well-known
endpoint. To learn more about what endpoints are returned, checkout the OIDCEndpoints
section.
1// This should be within an async function. 2const oidcEndpoints = await auth.getOIDCServiceEndpoints();
1getDecodedIDToken(userID?: string): Promise<DecodedIDTokenPayload>
userID: string
(optional)
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.
decodedIDTokenPayload: Promise<[DecodedIDTokenPayload](#DecodedIDTokenPayload)>
The decoded ID token payload.
This method decodes the payload of the id token and returns the decoded values.
1const decodedIDTokenPayload = await auth.getDecodedIDToken();
1getIDToken(userID?: string): Promise<string>
userID: string
(optional)
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.
idToken: Promise<string>
The id token.
This method returns the id token.
1const idToken = await auth.getIDToken();
1getBasicUserInfo(userID?: string): Promise<BasicUserInfo>
userID: string
(optional)
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.
basicUserInfo: Promise<[BasicUserInfo](#BasicUserInfo)>
An object containing basic user information obtained from the id token.
This method returns the basic user information obtained from the payload. To learn more about what information is returned, checkout the DecodedIDTokenPayload
model.
1// This should be used within an async function. 2const basicUserInfo = await auth.getBasicUserInfo();
1revokeAccessToken(userID?: string): Promise<AxiosResponse>
userID: string
(optional)
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.
A Promise that resolves with the response returned by the server.
This method clears the authentication data and sends a request to revoke the access token. You can use this method if you want to sign the user out of your application but not from the server.
1auth.revokeAccessToken().then((response)=>{ 2 console.log(response); 3}).catch((error)=>{ 4 console.error(error); 5})
1refreshAccessToken(userID?: string): Promise<TokenResponse>
userID: string
(optional)
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.
A Promise that resolves with the token response that contains the token information.
This method sends a refresh-token request and returns a promise that resolves with the token information. To learn more about what information is returned, checkout the TokenResponse
model. The existing authentication data in the store is automatically updated with the new information returned by this request.
1auth.refreshAccessToken().then((response)=>{ 2 console.log(response); 3}).catch((error)=>{ 4 console.error(error); 5})
1getAccessToken(userID?: string): Promise<string>
userID: string
(optional)
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.
accessToken: string
The access token.
This method returns the access token stored in the store. If you want to send a request to obtain the access token from the server, use the requestAccessToken
method.
1// This should be used within an async function. 2const accessToken = await auth.getAccessToken();
1requestCustomGrant(config: CustomGrantConfig, userID?: string): Promise<TokenResponse | AxiosResponse>
config: CustomGrantConfig
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
model.
userID: string
(optional)
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.
A Promise that resolves with the token information or the response returned by the server depending on the configuration passed.
This method can be used to send custom-grant requests to Asgardeo.
1 const config = { 2 attachToken: false, 3 data: { 4 client_id: "{{clientID}}", 5 grant_type: "account_switch", 6 scope: "{{scope}}", 7 token: "{{token}}", 8 }, 9 id: "account-switch", 10 returnResponse: true, 11 returnsSession: true, 12 signInRequired: true 13 } 14 15 auth.requestCustomGrant(config).then((response)=>{ 16 console.log(response); 17 }).catch((error)=>{ 18 console.error(error); 19 });
1isAuthenticated(userID?: string): Promise<boolean>
userID: string
(optional)
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.
isAuth: boolean
A boolean value that indicates of the user is authenticated or not.
This method returns a boolean value indicating if the user is authenticated or not.
1// This should be within an async function. 2const isAuth = await auth.isAuthenticated();
1getPKCECode(state: string, userID?: string): string
state: string
The state parameter that was passed in the authorization request.
userID: string
(optional)
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.
pkce: string
The PKCE code
This code returns the PKCE code generated when the authorization URL is generated by the getAuthorizationURL
method.
1const pkce = auth.getPKCECode(state);
1setPKCECode(pkce: string, state: string, userID?: string): void
string
The PKCE code generated by the getAuthorizationURL
method. 2. state: string
The state parameter that was passed in the authorization request. 3. userID: string
(optional)
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.
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
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
method can run successfully.
1auth.setPKCECode(pkce, state);
1static isSignOutSuccessful(signOutRedirectURL: string): boolean
This is a static method.
signOutRedirectURL: string
The URL to which the user is redirected to after signing out from the server.
isSignedOut: boolean
A boolean value indicating if the user has been signed out or not.
This method returns if the user has been successfully signed out or not. When a user signs out from the server, the user is redirected to the URL specified by the signOutRedirectURL
in the config object passed into the constructor of the AsgardeoAuthClient
. The server appends path parameters indicating if the sign-out is successful. This method reads the URL and returns if the sign-out is successful or not. So, make sure you pass as the argument the URL to which the user has been redirected to after signing out from the server.
1const isSignedOut = auth.isSignOutSuccessful(window.location.href);
1static didSignOutFail(signOutRedirectURL: string): boolean
This is a static method.
signOutRedirectURL: string
The URL to which the user is redirected to after signing out from the server.
didSignOutFail: boolean
A boolean value indicating if sign-out failed or not.
This method returns if sign-out failed or not. When a user signs out from the server, the user is redirected to the URL specified by the signOutRedirectURL
in the config object passed into the constructor of the AsgardeoAuthClient
. The server appends path parameters indicating if the sign-out is successful. This method reads the URL and returns if the sign-out failed or not. So, make sure you pass as the argument the URL to which the user has been redirected to after signing out from the server.
1const didSignOutFail = auth.didSignOutFail(window.location.href);
1updateConfig(config: Partial<AuthClientConfig<T>>): Promise<void>
AuthClientConfig<T>
The config object containing the attributes that can be used to configure the SDK. To learn more about the available attributes, refer to the AuthClientConfig>T>
model.
This method can be used to update the configurations passed into the constructor of the AsgardeoAuthClient
. Please note that every attribute in the config object passed as the argument here is optional. Use this method if you want to update certain attributes after instantiating the class.
1// This should be within an async function. 2await auth.updateConfig({ 3 signOutRedirectURL: "http://localhost:3000/sign-out" 4});
Since the SDK was developed with the view of being able to support various platforms such as mobile apps, browsers and node.js servers, the SDK allows developers to use their preferred mode of storage. To that end, the SDK allows you to pass a store object when instantiating the AsgardeoAuthClient
. This store object contains methods that can be used to store, retrieve and delete data. The SDK provides a Store interface that you can implement to create your own Store class. You can refer to the Store
section to learn more about the Store
interface.
There are three methods that are to be implemented by the developer. They are
setData
getData
removeData
The setData
method is used to store data. The getData
method is used to retrieve data. The removeData
method is used to delete data. The SDK converts the data to be stored into a JSON string internally and then calls the setData
method to store the data. The data is represented as a key-value pairs in the SDK. The SDK uses four keys internally and you can learn about them by referring to the Data Layer section. So, every JSON stringified data value is supposed to be stored against the passed key in the data store. A sample implementation of the Store
class using the browser session storage is given here.
1class SessionStore implements Store { 2 public setData(key: string, value: string): void { 3 sessionStorage.setItem(key, value); 4 } 5 6 public getData(key: string): string { 7 return sessionStorage.getItem(key); 8 } 9 10 public removeData(key: string): void { 11 sessionStorage.removeItem(key); 12 } 13}
The data layer is implemented within the SDK encapsulating the Store
object passed into the constructor. The data layer acts as the interface between the SDK and the store object and provides a more developer-friendly interface to store, retrieve and delete data. Four keys are used to store four different sets of data. The keys are:
SessionData
to get the full list of data stored..well-known
endpoint. Refer to OIDCProviderMetaData
for the full list of data stored.AuthClientConfig<T>
for the full list of data stored.All these four keys get methods to set, get and remove data as whole. In addition to this, all these keys get methods to set, get, and remove specific data referred to by their respective keys. The following table describes the methods provided by the data layer.
Method | Arguments | Returns | Description |
---|---|---|---|
setSessionData | sessionData: SessionData | Promise<void> | Saves session data in bulk. |
setOIDCProviderMetaData | oidcProviderMetaData: OIDCProviderMetaData | Promise<void> | Saves OIDC Provider Meta data in bulk. |
setConfigData | config: AuthClientConfig<T> | Promise<void> | Saves config data in bulk. |
setTemporaryData | data: TemporaryData | Promise<void> | Saves temporary data in bulk. |
getSessionData | Promise< SessionData > | Retrieves session data in bulk. | |
getOIDCProviderMetaData | Promise< OIDCProviderMetaData > | Retrieves OIDC Provider Meta data in bulk. | |
getConfigData | Promise< AuthClientConfig<T> > | Retrieves config data in bulk. | |
getTemporaryData | Promise< { [key: string ]: StoreValue}> | Retrieves temporary data in bulk. | |
removeSessionData | Promise<void> | Removes session data in bulk. | |
removeOIDCProviderMetaData | Promise<void> | Removes OIDC Provider Meta data in bulk. | |
removeConfigData | Promise<void> | Removes config data in bulk. | |
removeTemporaryData | Promise<void> | Removes temporary data in bulk. | |
setSessionDataParameter | key: keyof SessionData , value: StoreValue | Promise<void> | Saves the passed data against the specified key in the session data. |
setOIDCProviderMetaDataParameter | key: keyof OIDCProviderMetaData , value: StoreValue | Promise<void> | Saves the passed data against the specified key in the OIDC Provider Meta data. |
setConfigDataParameter | key: keyof AuthClientConfig<T> , value: StoreValue | Promise<void> | Saves the passed data against the specified key in the config data. |
setTemporaryDataParameter | key: string , value: StoreValue | Promise<void> | Saves the passed data against the specified key in the temporary data. |
getSessionDataParameter | key: keyof SessionData | Promise< StoreValue > | Retrieves the data for the specified key from the session data. |
getOIDCProviderMetaDataParameter | key: keyof OIDCProviderMetaData | Promise< StoreValue > | Retrieves the data for the specified key from the OIDC Provider Meta data. |
getConfigDataParameter | key: keyof AuthClientConfig<T> | Promise< StoreValue > | Retrieves the data for the specified key from the config data. |
getTemporaryDataParameter | key: string | Promise< StoreValue > | Retrieves the data for the specified key from the temporary data. |
removeSessionDataParameter | key: keyof SessionData | Promise<void> | Removes the data with the specified key from the session data. |
removeOIDCProviderMetaDataParameter | key: keyof OIDCProviderMetaData | Promise<void> | Removes the data with the specified key from the OIDC Provider Meta data. |
removeConfigDataParameter | key: keyof AuthClientConfig<T> | Promise<void> | Removes the data with the specified key from the config data. |
removeTemporaryDataParameter | key: string | Promise<void> | Removes the data with the specified key from the temporary data. |
The CryptoUtils interface defines the methods required to perform cryptographic operations such as producing a PKCE code and verifying ID tokens. The following table describes the methods provided by the CryptoUtils interface.
Method | Arguments | Returns | Description |
---|---|---|---|
base64urlEncode | input: T | string | Encodes the passed input string to a base64url encoded string. |
base64urlDecode | input: string | string | Decodes the passed input string from a base64url encoded string. |
hashSha256 | input: string | T | Hashes the passed input string using SHA-256. |
generateRandomBytes | length: number | T | Generates random bytes of the specified length. |
verifyJwt | jwt: string , jwk: JWKInterface | Promise<boolean> | Verifies the passed JWT using the passed JWK. |
NOTE: The return type of the hashSha256
and generateRandomBytes
method should be the same as the type of the argument of the base64urlEncode
method.
These methods should be implemented in a class and the instance of the class should be passed as an argument into the constructor of AsgardeoAuthClient
.
This model has the following attributes.
Attribute | Required/Optional | Type | Default Value | Description |
---|---|---|---|---|
signInRedirectURL | Required | string | "" | The URL to redirect to after the user authorizes the client app. eg: https//localhost:3000/sign-in |
signOutRedirectURL | Optional | string | The signInRedirectURL URL will be used if this value is not provided. | The URL to redirect to after the user |
clientHost | Optional | string | The origin of the client app obtained using window.origin | The hostname of the client app. eg: https://localhost:3000 |
clientID | Required | string | "" | The client ID of the OIDC application hosted in the Asgardeo. |
clientSecret | Optional | string | "" | The client secret of the OIDC application |
enablePKCE | Optional | boolean | true | Specifies if a PKCE should be sent with the request for the authorization code. |
prompt | Optional | string | "" | Specifies the prompt type of an OIDC request |
responseMode | Optional | ResponseMode | "query" | Specifies the response mode. The value can either be query or form_post |
scope | Optional | string[] | ["openid"] | Specifies the requested scopes. |
baseUrl | Required (If wellKnownEndpoint or endpoints is not provided) | string | "" | The origin of the Identity Provider. eg: https://api.asgardeo.io/t/<org_name>. |
endpoints | Optional (Required to provide all endpoints, if wellKnownEndpoint or baseUrl is not provided) | OIDCEndpoints | OIDC Endpoints Default Values | The OIDC endpoint URLs. The SDK will try to obtain the endpoint URLS |
wellKnownEndpoint | Optional (Required if baseUrl or endpoints is not provided) | string | "/oauth2/token/.well-known/openid-configuration" | The URL of the .well-known endpoint. |
validateIDToken | Optional | boolean | true | Allows you to enable/disable JWT ID token validation after obtaining the ID token. |
validateIDTokenIssuer (optional) | boolean | true | Allows you to enable/disable JWT ID token issuer validation after obtaining the ID token (This config is applicable only when JWT ID token validation is enabled). | |
clockTolerance | Optional | number | 60 | Allows you to configure the leeway when validating the id_token. |
sendCookiesInRequests | Optional | boolean | true | Specifies if cookies should be sent in the requests. |
sendIdTokenInLogoutRequest | Optional | boolean | false | Specifies if id_token_hint parameter should be sent in the logout request instead of the default client_id parameter. |
The AuthClientConfig<T>
can be extended by passing an interface as the generic type. For example, if you want to add an attribute called foo
to the config object, you can create an interface called Bar
and pass that as the generic type into the AuthClientConfig<T>
interface.
1interface Bar { 2 foo: string 3} 4 5const config: AuthClientConfig<Bar> ={ 6 ... 7}
Method | Required/Optional | Arguments | Returns | Description |
---|---|---|---|---|
setData | Required | key: string , value: string | Promise<void> | This method saves the passed value to the store. The data to be saved is JSON stringified so will be passed by the SDK as a string. |
getData | Required | key: string |string | This method retrieves the data from the store and returns a Promise that resolves with it. Since the SDK stores the data as a JSON string, the returned value will be a string. | |
removeData | Required | key: string | Promise<void> | Removes the data with the specified key from the store. |
Method | Required/Optional | Type | Default Value | Description |
---|---|---|---|---|
fidp | Optional | string | "" | The fidp parameter that can be used to redirect a user directly to an IdP's sign-in page. |
forceInit | Optional | boolean | false | Forces obtaining the OIDC endpoints from the .well-known endpoint. A request to this endpoint is not sent if a request has already been sent. This forces a request. |
key: string | Optional | string | boolean | "" | Any key-value pair to be appended as path parameters to the authorization URL. |
Method | Type | Description |
---|---|---|
accessToken | string | The access token. |
idToken | string | The id token. |
expiresIn | string | The expiry time in seconds. |
scope | string | The scope of the token. |
refreshToken | string | The refresh token. |
tokenType | string | The token type. |
Method | Type | Default Value | Description |
---|---|---|---|
authorizationEndpoint | string | "/oauth2/authorize" | The authorization endpoint. |
tokenEndpoint | string | "/oauth2/token" | The token endpoint. |
userinfoEndpoint | string | "" | The user-info endpoint. |
jwksUri | string | "/oauth2/jwks" | The JWKS URI. |
registrationEndpoint | string | "" | The registration endpoint. |
revocationEndpoint | string | "/oauth2/revoke" | The token-revocation endpoint. |
introspectionEndpoint | string | "" | The introspection endpoint. |
checkSessionIframe | string | "/oidc/checksession" | The check-session endpoint. |
endSessionEndpoint | string | "/oidc/logout" | The end-session endpoint. |
issuer | string | "" | The issuer of the token. |
Method | Type | Description |
---|---|---|
aud | string | string[] | The audience. |
sub | string | The subject. This is the username of the user. |
iss | string | The token issuer. |
string | The email address. | |
preferred_username | string | The preferred username. |
tenant_domain | string | The tenant domain to which the user belongs. |
Attribute | Required/Optional | Type | Default Value | Description |
---|---|---|---|---|
id | Required | string | "" | Every custom-grant request should have an id. This attributes takes that id. |
data | Required | any | null | The data that should be sent in the body of the custom-grant request. You can use template tags to send session information. Refer to the Custom Grant Template Tags section for more details. |
signInRequired | Required | boolean | false | Specifies if the user should be sign-in or not to dispatch this custom-grant request. |
attachToken | Required | boolean | false | Specifies if the access token should be attached to the header of the request. 💡 Note : If the request is credentialed, server must specify a domain, and cannot use wild carding. This would lead to CORS errors and if you intend to bypass this behavior per request, add wihCredentials: false to the httpRequest config. |
returnsSession | Required | boolean | false | Specifies if the the request returns session information such as the access token. |
tokenEndpoint | Optional | string | null | Token endpoint is an optional parameter which can be used to provide an optional token endpoint that will be used instead of default token endpoint. |
Session information can be attached to the body of a custom-grant request using template tags. This is useful when the session information is not exposed outside the SDK but you want such information to be used in custom-grant requests. The following table lists the available template tags.
Tag | Data |
---|---|
"{{token}}" | The access token. |
{{username}}" | The username. |
"{{scope}}" | The scope. |
{{clientID}}" | The client ID. |
"{{clientSecret}}" | The client secret. |
Attribute | Type | description |
---|---|---|
access_token | string | The access token. |
id_token | string | The id token. |
expires_in | string | The expiry time. |
scope | string | The scope. |
refresh_token | string | The refresh token. |
token_type | string | The token type. |
session_state | string | The session state obtained after authentication. |
created_at | number | The time when the session was created. |
Attribute | Type | description |
---|---|---|
issuer | string | URL using the https scheme with no query or fragment component that the OP asserts as its Issuer Identifier. |
authorization_endpoint | string | URL of the OP's OAuth 2.0 Authorization Endpoint. |
token_endpoint | string | URL of the OP's OAuth 2.0 Token Endpoint. |
userinfo_endpoint | string | URL of the OP's UserInfo Endpoint. |
jwks_uri | string | URL of the OP's JSON Web Key Set [JWK] document. This contains the signing key(s) the RP uses to validate signatures from the OP. |
registration_endpoint | string | URL of the OP's Dynamic Client Registration Endpoint |
scopes_supported | string[] | JSON array containing a list of the OAuth 2.0 [RFC6749] scope values that this server supports. |
response_types_supported | string[] | JSON array containing a list of the OAuth 2.0 response_type values that this OP supports. |
response_modes_supported | string[] | JSON array containing a list of the OAuth 2.0 response_mode values that this OP supports. |
grant_types_supported | string[] | JSON array containing a list of the OAuth 2.0 Grant Type values that this OP supports. |
acr_values_supported | string[] | JSON array containing a list of the Authentication Context Class References that this OP supports. |
subject_types_supported | string[] | JSON array containing a list of the Subject Identifier types that this OP supports. |
id_token_signing_alg_values_supported | string[] | JSON array containing a list of the JWS signing algorithms(alg values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT]. |
id_token_encryption_alg_values_supported | string[] | JSON array containing a list of the JWE encryption algorithms (alg values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT]. |
id_token_encryption_enc_values_supported | string[] | JSON array containing a list of the JWE encryption algorithms (enc values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT]. |
userinfo_signing_alg_values_supported | string[] | JSON array containing a list of the JWS [JWS] signing algorithms (alg values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT]. |
userinfo_encryption_alg_values_supported | string[] | JSON array containing a list of the JWE [JWE] encryption algorithms (alg values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT]. |
userinfo_encryption_enc_values_supported | string[] | JSON array containing a list of the JWE encryption algorithms (enc values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT] |
request_object_signing_alg_values_supported | string[] | JSON array containing a list of the JWS signing algorithms (alg values) supported by the OP for Request Objects |
request_object_encryption_alg_values_supported | string[] | JSON array containing a list of the JWE encryption algorithms (alg values) supported by the OP for Request Objects. |
request_object_encryption_enc_values_supported | string[] | JSON array containing a list of the JWE encryption algorithms (enc values) supported by the OP for Request Objects. |
token_endpoint_auth_methods_supported | string[] | JSON array containing a list of Client Authentication methods supported by this Token Endpoint. |
token_endpoint_auth_signing_alg_values_supported | string[] | JSON array containing a list of the JWS signing algorithms (alg values) supported by the Token Endpoint for the signature on the JWT [JWT] used to authenticate the Client at the Token Endpoint for the private_key_jwt and client_secret_jwt authentication methods. |
display_values_supported | string[] | JSON array containing a list of the display parameter values that the OpenID Provider supports. |
claim_types_supported | string[] | JSON array containing a list of the Claim Types that the OpenID Provider supports. |
claims_supported | string[] | JSON array containing a list of the Claim Names of the Claims that the OpenID Provider MAY be able to supply values for. |
No vulnerabilities found.
No security vulnerabilities found.