adal-node

  • Version 0.2.4
  • Published
  • 240 kB
  • 8 dependencies
  • Apache-2.0 license

Install

npm i adal-node
yarn add adal-node
pnpm add adal-node

Overview

Windows Azure Active Directory Client Library for node

Index

Functions

function createAuthenticationContext

createAuthenticationContext: (
authority: string,
validateAuthority?: boolean
) => AuthenticationContext;
  • Creates a new AuthenticationContext object. By default the authority will be checked against a list of known Azure Active Directory authorities. If the authority is not recognized as one of these well known authorities then token acquisition will fail. This behavior can be turned off via the validateAuthority parameter below.

    Parameter authority

    A URL that identifies a token authority.

    Parameter validateAuthority

    Turns authority validation on or off. This parameter default to true.

    Returns

    {AuthenticationContext} A new authentication context.

function createAuthenticationParametersFromHeader

createAuthenticationParametersFromHeader: (
challenge: string
) => AuthenticationParameters;
  • Creates an AuthenticationParameters object from the contents of a www-authenticate header received from a HTTP 401 response from a resource server.

    Parameter challenge

    The content fo the www-authenticate header. {AuthenticationParameters} An AuthenticationParameters object containing the parsed values from the header.

function createAuthenticationParametersFromResponse

createAuthenticationParametersFromResponse: (
response: http.IncomingMessage
) => AuthenticationParameters;
  • Create an AuthenticationParameters object from a node http.IncomingMessage object that was created as a result of a request to a resource server. This function expects the response to contain a HTTP 401 error code with a www-authenticate header.

    Parameter response

    A response from a http request to a resource server. {AuthenticationParameters}

function createAuthenticationParametersFromUrl

createAuthenticationParametersFromUrl: (
url: string,
callback: (error: Error, parameters: AuthenticationParameters) => void,
correlationId?: string
) => AuthenticationParameters;
  • Creates an AuthenticationParameters object by sending a get request to the url passed to this function, and parsing the resulting http 401 response.

    Parameter url

    The url of a resource server.

    Parameter callback

    Called on error or request completion.

    Parameter correlationId

    An optional correlationId to pass along with the request and to include in any logs.

function getGlobalADALOptions

getGlobalADALOptions: () => any;

    function setGlobalADALOptions

    setGlobalADALOptions: () => any;

      Classes

      class AuthenticationContext

      class AuthenticationContext {}

        constructor

        constructor(
        authority: string,
        validateAuthority?: boolean,
        cache?: TokenCache,
        aadApiVersion?: string
        );
        • Creates a new AuthenticationContext object. By default the authority will be checked against a list of known Azure Active Directory authorities. If the authority is not recognized as one of these well known authorities then token acquisition will fail. This behavior can be turned off via the validateAuthority parameter below.

          Parameter authority

          A URL that identifies a token authority.

          Parameter validateAuthority

          Turns authority validation on or off. This parameter default to true.

          Parameter cache

          Sets the token cache used by this AuthenticationContext instance. If this parameter is not set then a default, in memory cache is used. The default in memory cache is global to the process and is shared by all AuthenticationContexts that are created with an empty cache parameter. To control the scope and lifetime of a cache you can either create a MemoryCache instance and pass it when constructing an AuthenticationContext or implement a custom TokenCache and pass that. Cache instances passed at AuthenticationContext construction time are only used by that instance of the AuthenticationContext and are not shared unless it has been manually passed during the construction of other AuthenticationContexts.

        property authority

        authority: string;
        • {string} authority A URL that identifies a token authority.

        property cache

        cache: TokenCache;
        • {TokenCache} cache The token cache used by this AuthenticationContext instance

        property correlationId

        correlationId: string;
        • {string} correlationId The correlation id that will be used for the next acquireToken request.

        property options

        options: any;
        • {any} options Options that are applied to requests generated by this AuthenticationContext instance.

        method acquireToken

        acquireToken: (
        resource: string,
        userId: string,
        clientId: string,
        callback: AcquireTokenCallback
        ) => void;
        • Gets a token for a given resource.

          Parameter resource

          A URI that identifies the resource for which the token is valid.

          Parameter userId

          The username of the user on behalf this application is authenticating.

          Parameter clientId

          The OAuth client id of the calling application.

          Parameter callback

          The callback function.

        method acquireTokenWithAuthorizationCode

        acquireTokenWithAuthorizationCode: (
        authorizationCode: string,
        redirectUri: string,
        resource: string,
        clientId: string,
        clientSecret: string,
        callback: AcquireTokenCallback
        ) => void;
        • Gets a token for a given resource.

          Parameter authorizationCode

          An authorization code returned from a client.

          Parameter redirectUri

          The redirect uri that was used in the authorize call.

          Parameter resource

          A URI that identifies the resource for which the token is valid.

          Parameter clientId

          The OAuth client id of the calling application.

          Parameter clientSecret

          The OAuth client secret of the calling application.

          Parameter callback

          The callback function.

        method acquireTokenWithClientCertificate

        acquireTokenWithClientCertificate: (
        resource: string,
        clientId: string,
        certificate: string,
        thumbprint: string,
        callback: AcquireTokenCallback
        ) => void;
        • Gets a new access token using via a certificate credential.

          Parameter resource

          A URI that identifies the resource for which the token is valid.

          Parameter clientId

          The OAuth client id of the calling application.

          Parameter certificate

          A PEM encoded certificate private key.

          Parameter thumbprint

          A hex encoded thumbprint of the certificate.

          Parameter callback

          The callback function.

        method acquireTokenWithClientCredentials

        acquireTokenWithClientCredentials: (
        resource: string,
        clientId: string,
        clientSecret: string,
        callback: AcquireTokenCallback
        ) => void;
        • Gets a token for a given resource.

          Parameter resource

          A URI that identifies the resource for which the token is valid.

          Parameter clientId

          The OAuth client id of the calling application.

          Parameter clientSecret

          The OAuth client secret of the calling application.

          Parameter callback

          The callback function.

        method acquireTokenWithDeviceCode

        acquireTokenWithDeviceCode: (
        resource: string,
        clientId: string,
        userCodeInfo: UserCodeInfo,
        callback: AcquireTokenCallback
        ) => void;
        • Gets a new access token using via a device code. This method doesn't look up the cache, it only stores the returned token into cache. To look up cache before making a new request, please use acquireToken.

          Parameter clientId

          The OAuth client id of the calling application.

          Parameter userCodeInfo

          Contains device_code, retry interval, and expire time for the request for get the token.

          Parameter callback

          The callback function.

        method acquireTokenWithRefreshToken

        acquireTokenWithRefreshToken: {
        (
        refreshToken: string,
        clientId: string,
        resource: string,
        callback: AcquireTokenCallback
        ): void;
        (
        refreshToken: string,
        clientId: string,
        clientSecret: string,
        resource: string,
        callback: AcquireTokenCallback
        ): void;
        };
        • Gets a new access token via a previously issued refresh token.

          Parameter refreshToken

          A refresh token returned in a tokne response from a previous invocation of acquireToken.

          Parameter clientId

          The OAuth client id of the calling application.

          Parameter clientSecret

          The OAuth client secret of the calling application. (Note: this parameter is a late addition. This parameter may be ommitted entirely so that applications built before this change will continue to work unchanged.)

          Parameter resource

          The OAuth resource for which a token is being request. This parameter is optional and can be set to null.

          Parameter callback

          The callback function.

        method acquireTokenWithUsernamePassword

        acquireTokenWithUsernamePassword: (
        resource: string,
        username: string,
        password: string,
        clientId: string,
        callback: AcquireTokenCallback
        ) => void;
        • Gets a token for a given resource.

          Parameter resource

          A URI that identifies the resource for which the token is valid.

          Parameter username

          The username of the user on behalf this application is authenticating.

          Parameter password

          The password of the user named in the username parameter.

          Parameter clientId

          The OAuth client id of the calling application.

          Parameter callback

          The callback function.

        method acquireUserCode

        acquireUserCode: (
        resource: string,
        clientId: string,
        language: string,
        callback: AcquireUserCodeCallback
        ) => void;
        • Gets the userCodeInfo which contains user_code, device_code for authenticating user on device.

          Parameter resource

          A URI that identifies the resource for which the device_code and user_code is valid for.

          Parameter clientId

          The OAuth client id of the calling application.

          Parameter language

          The language code specifying how the message should be localized to.

          Parameter callback

          The callback function.

        method cancelRequestToGetTokenWithDeviceCode

        cancelRequestToGetTokenWithDeviceCode: (
        userCodeInfo: UserCodeInfo,
        callback: AcquireTokenCallback
        ) => void;
        • Cancels the polling request to get token with device code.

          Parameter userCodeInfo

          Contains device_code, retry interval, and expire time for the request for get the token.

          Parameter callback

          The callback function.

        class AuthenticationParameters

        class AuthenticationParameters {}
        • Describes the parameters that are parsed from an OAuth challenge in the www-authenticate header.

        constructor

        constructor(authorizationUri: string, resource: string);
        • Provides an instance of AuthenticationParameters

          Parameter authorizationUri

          The URI of an authority that can issues tokens for the resource that issued the challenge.

          Parameter resource

          The resource for a which a token should be requested from the authority.

        property authorizationUri

        authorizationUri: string;

          property resource

          resource: string;

            class Logging

            class Logging {}

              property LOGGING_LEVEL

              static LOGGING_LEVEL: LoggingLevel;
              • {LoggingLevel} LOGGING_LEVEL Provides information about the logging levels. ERROR: 0, WARN: 1, INFO: 2, VERBOSE: 3

              method getLoggingOptions

              static getLoggingOptions: () => LoggingOptions;
              • Get's the current global logging options. {LoggingOptions}

              method setLoggingOptions

              static setLoggingOptions: (options: LoggingOptions) => void;
              • Sets global logging options for ADAL.

                Parameter options

              class MemoryCache

              class MemoryCache implements TokenCache {}
              • MemoryCache - Describes the in memory implementation of the token cache.

              constructor

              constructor();
              • Creates an instance of MemoryCache

              method add

              add: (
              entries: TokenResponse[],
              callback: (err: Error, result: boolean) => void
              ) => void;
              • Adds a collection of entries to the cache in a single batch operation.

                Parameter entries

                An array of entries to add to the cache.

                Parameter callback

                This function is called when the operation is complete. Any error is provided as the first parameter.

              method find

              find: (query: any, callback: (err: Error, results: any[]) => void) => void;
              • Finds all entries in the cache that match all of the passed in values.

                Parameter query

                This object will be compared to each entry in the cache. Any entries that match all of the values in this object will be returned. All the values in the passed in object must match values in a potentialy returned object exactly. The returned object may have more values than the passed in query object. Please take a look at http://underscorejs.org/#where for an example on how to provide query.

                Parameter callback

              method remove

              remove: (
              entires: TokenResponse[],
              callback: (err: Error, result: null) => void
              ) => void;
              • Removes a collection of entries from the cache in a single batch operation.

                Parameter entries

                An array of cache entries to remove.

                Parameter callback

                This function is called when the operation is complete. Any error is provided as the first parameter.

              Interfaces

              interface ErrorResponse

              interface ErrorResponse {}
              • This will be returned in case the OAuth 2 service returns an error. ErrorResponse {string} [error] A server error. {string} [errorDescription] A description of the error returned.

              property error

              error: string;

                property errorDescription

                errorDescription: string;

                  interface LoggingOptions

                  interface LoggingOptions {}
                  • LoggingOptions Logging {LoggingCallback} [log] The function to call when ADAL generates a log entry. {LoggingLevel} [level] The maximum level of log entries to generate. {boolean} [loggingWithPII] This value indicts if personal identity related information such as token and claims should be logged. The default value is false.

                  property level

                  level?: LoggingLevel;

                    property log

                    log?: LoggingCallback;

                      property loggingWithPII

                      loggingWithPII?: boolean;

                        interface TokenCache

                        interface TokenCache {}
                        • This is an interface that can be implemented to provide custom token cache persistence.

                          TokenCache

                          Modifiers

                          • @public

                        method add

                        add: (
                        entries: TokenResponse[],
                        callback: (err: Error, result: boolean) => void
                        ) => void;
                        • Adds a collection of entries to the cache in a single batch operation.

                          Parameter entries

                          An array of entries to add to the cache.

                          Parameter callback

                          This function is called when the operation is complete. Any error is provided as the first parameter.

                        method find

                        find: (query: any, callback: (err: Error, results: any[]) => void) => void;
                        • Finds all entries in the cache that match all of the passed in values.

                          Parameter query

                          This object will be compared to each entry in the cache. Any entries that match all of the values in this object will be returned. All the values in the passed in object must match values in a potentialy returned object exactly. The returned object may have more values than the passed in query object. Please take a look at http://underscorejs.org/#where for an example on how to provide query.

                          Parameter callback

                        method remove

                        remove: (
                        entires: TokenResponse[],
                        callback: (err: Error, result: null) => void
                        ) => void;
                        • Removes a collection of entries from the cache in a single batch operation.

                          Parameter entries

                          An array of cache entries to remove.

                          Parameter callback

                          This function is called when the operation is complete. Any error is provided as the first parameter.

                        interface TokenResponse

                        interface TokenResponse {}
                        • Contains tokens and metadata upon successful completion of an acquireToken call. TokenResponse

                        property accessToken

                        accessToken: string;
                        • {string} accessToken The returned access token.

                        property createdOn

                        createdOn?: Date | string;
                        • {Date} [createdOn] The date on which the access token was created.

                        property error

                        error?: any;
                        • {any} [error] Provides information about error if any.

                        property errorDescription

                        errorDescription?: any;
                        • {any} [errorDescription] Short description about error if any.

                        property expiresIn

                        expiresIn: number;
                        • {int} expiresIn The amount of time, in seconds, for which the token is valid.

                        property expiresOn

                        expiresOn: Date | string;
                        • {Date} expiresOn The Date on which the access token expires.

                        property familyName

                        familyName?: string;
                        • {string} [familyName] The family name of the principal represented by the access token.

                        property givenName

                        givenName?: string;
                        • {string} [givenName] The given name of the principal represented by the access token.

                        property identityProvider

                        identityProvider?: string;
                        • {string} [identityProvider] Identifies the identity provider that issued the access token.

                        property isUserIdDisplayable

                        isUserIdDisplayable?: boolean;
                        • {boolean} [isUserIdDisplayable] Indicates whether the user_id property will be meaningful if displayed to a user.

                        property oid

                        oid?: string;
                        • {string} [oid] The object id of the user in the tenant

                        property refreshToken

                        refreshToken?: string;
                        • {string} [refreshToken] A refresh token.

                        property resource

                        resource: string;
                        • {string} resource The resource for which the token was requested for. Example: 'https://management.core.windows.net/'.

                        property tenantId

                        tenantId?: string;
                        • {string} [tenantId] The identifier of the tenant under which the access token was issued.

                        property tokenType

                        tokenType: string;
                        • {string} tokenType The type of token returned. Example 'Bearer'.

                        property userId

                        userId?: string;
                        • {string} [userId] An id for the user. May be a displayable value if is_user_id_displayable is true.

                        index signature

                        [x: string]: any;

                          interface UserCodeInfo

                          interface UserCodeInfo {}
                          • Describes the user code information that is provided by ADAL while authenticating via DeviceCode.

                          property deviceCode

                          deviceCode: string;

                            property error

                            error?: any;

                              property errorDescription

                              errorDescription?: any;

                                property expiresIn

                                expiresIn: number;

                                  property interval

                                  interval: number;

                                    property message

                                    message: string;

                                      property userCode

                                      userCode: string;

                                        property verificationUrl

                                        verificationUrl: string;

                                          index signature

                                          [x: string]: any;

                                            Type Aliases

                                            type AcquireTokenCallback

                                            type AcquireTokenCallback = (
                                            error: Error,
                                            response: TokenResponse | ErrorResponse
                                            ) => void;
                                            • This is the callback that is passed to all acquireToken variants below. AcquireTokenCallback

                                              Parameter error

                                              If the request fails this parameter will contain an Error object.

                                              Parameter response

                                              On a succesful request returns a TokenResposne.

                                            type AcquireUserCodeCallback

                                            type AcquireUserCodeCallback = (error: Error, response: UserCodeInfo) => void;
                                            • This is the callback that is passed to all acquireUserCode method below. AcquireTokenCallback

                                              Parameter error

                                              If the request fails this parameter will contain an Error object.

                                              Parameter response

                                              On a succesful request returns a UserCodeInfo.

                                            type LoggingCallback

                                            type LoggingCallback = (level: LoggingLevel, message: string, error?: Error) => void;
                                            • LoggingCallback Logging

                                              Parameter level

                                              The level of this log entry.

                                              Parameter message

                                              The text content of the log entry.

                                              Parameter error

                                              An Error object if this is an ERROR level log entry.

                                            type LoggingLevel

                                            type LoggingLevel = 0 | 1 | 2 | 3;
                                            • Describes the available logging levels. ERROR: 0, WARN: 1, INFO: 2, VERBOSE: 3 {number}

                                            Package Files (1)

                                            Dependencies (8)

                                            Dev Dependencies (10)

                                            Peer Dependencies (0)

                                            No peer dependencies.

                                            Badge

                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/adal-node.

                                            • Markdown
                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/adal-node)
                                            • HTML
                                              <a href="https://www.jsdocs.io/package/adal-node"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>