Class

Token (cloud-services-core)

@ckeditor/ckeditor-cloud-services-core/src/token

class

Class representing the token used for communication with CKEditor Cloud Services. Value of the token is retrieving from the specified URL and is refreshed every 1 hour by default.

Filtering

Properties

  • value : String

    readonly observable

    Value of the token. The value of the token is null if initValue is not provided or init method was not called. create method creates token with initialized value from url.

  • _options : Object

    private

  • _refresh : String | function

    private

    Base refreshing function.

Methods

  • constructor( tokenUrlOrRefreshToken, options = { [options.initValue], [options.autoRefresh] } )

    Creates Token instance. Method init should be called after using the constructor or use create method instead.

    Parameters

    tokenUrlOrRefreshToken : String | function

    Endpoint address to download the token or a callback that provides the token. If the value is a function it has to match the refreshToken interface.

    options : Object
    Properties
    [ options.initValue ] : String

    Initial value of the token.

    [ options.autoRefresh ] : Boolean

    Specifies whether to start the refresh automatically.

    Defaults to true

  • destroy()

    Destroys token instance. Stops refreshing.

  • init() → Promise.<Token>

    Initializes the token.

    Returns

    Promise.<Token>
  • refreshToken() → Promise.<String>

    Refresh token method. Useful in a method form as it can be override in tests.

    Returns

    Promise.<String>
  • _getTokenRefreshTimeoutTime() → Number

    protected

    Returns token refresh timeout time calculated from expire time in the token payload.

    If the token parse fails or the token payload doesn't contain, the default DEFAULT_TOKEN_REFRESH_TIMEOUT_TIME is returned.

    Returns

    Number
  • _registerRefreshTokenTimeout()

    protected

    Registers a refresh token timeout for the time taken from token.

  • _validateTokenValue( tokenValue )

    protected

    Checks whether the provided token follows the JSON Web Tokens (JWT) format.

    Parameters

    tokenValue : String

    The token to validate.

Static methods

  • create( tokenUrlOrRefreshToken, options = { [options.initValue], [options.autoRefresh] } ) → Promise.<Token>

    static

    Creates a initialized Token instance.

    Parameters

    tokenUrlOrRefreshToken : String | function

    Endpoint address to download the token or a callback that provides the token. If the value is a function it has to match the refreshToken interface.

    options : Object
    Properties
    [ options.initValue ] : String

    Initial value of the token.

    [ options.autoRefresh ] : Boolean

    Specifies whether to start the refresh automatically.

    Defaults to true

    Returns

    Promise.<Token>

Events

  • change:value( eventInfo, name, value, oldValue )

    Fired when the value property changed value.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

    name : String

    Name of the changed property (value).

    value : String

    New value of the value property with given key or null, if operation should remove property.

    oldValue : String

    Old value of the value property with given key or null, if property was not set before.