Class

Token (cloud-services)

@ckeditor/ckeditor5-cloud-services/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

  • readonly observable

    value : String

    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.

  • private

    _options : Object

  • private

    _refresh : String | function

    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>
  • protected

    _getTokenRefreshTimeoutTime() → Number

    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
  • protected

    _registerRefreshTokenTimeout()

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

  • protected

    _validateTokenValue( tokenValue )

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

    Parameters

    tokenValue : String

    The token to validate.

Static methods

  • static

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

    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.