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.refreshInterval], [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.refreshInterval ] : Number

    Delay between refreshes. Default 1 hour.

    Defaults to 3600000

    [ 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>
  • _startRefreshing()

    protected

    Starts value refreshing every refreshInterval time.

  • _stopRefreshing()

    protected

    Stops value refreshing.

Static methods

  • create( tokenUrlOrRefreshToken, options = { [options.initValue], [options.refreshInterval], [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.refreshInterval ] : Number

    Delay between refreshes. Default 1 hour.

    Defaults to 3600000

    [ 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.