Options
All
  • Public
  • Public/Protected
  • All
Menu
description

The dApp basic OAuth driver. This class is used to determine communication, transport and process that are used to connect and integrate to custom providers.

since

v0.3.0

Hierarchy

Implements

Index

Constructors

Properties

codeFieldName: string = "code"

The driver's codeFieldName. This field indicates the name of the code field in this driver. Its value should always be 'code'.

access

protected

var

{string}

dataFieldName: string = "state"

The driver's dataFieldName. This field indicates the name of the data field in this driver. Its value should always be 'state'.

access

protected

var

{string}

httpService: HttpRequestHandler

The driver's HTTP service. It's a handler for HTTP requests and contains methods for executing remote API calls, e.g. calling a GET HTTP API endpoint.

access

protected

var

{HttpRequestHandler}

name: string
usesSecondsUTC: boolean = false

The driver's value to determine whether seconds are used to express UTC timestamps (if set to false, milliseconds are used). This field indicates the type of timestamp returned with this driver.

By default, as defined below, we expect OAuth drivers to not use seconds and instead use milliseconds. Extending driver classes can override this field value to specify the use of seconds instead.

access

protected

var

{boolean}

Accessors

  • get codeField(): string
  • get dataField(): string
  • get providerName(): string
  • get usesUTCSecondsToEpoch(): boolean
  • Getter that determines whether this driver uses seconds (rather than milliseconds) to express a timestamp in UTC format.

    access

    public

    Returns boolean

    Whether this driver uses seconds to express UTC timestamps.

Methods

  • buildAuthorizeQuery(data: string): string
  • Method to return the authorize query to this driver's provider. This is the query parameters that will be included after the authorized url.

    Note that it contain 3 fields client_id, redirect_uri and state (this driver's dataField).

    access

    protected

    Parameters

    • data: string

      The data value to include in this query.

    Returns string

    The full query parameters.

  • executeRequest(accessToken: string, endpointUri: string, method?: HttpMethod, body?: any, options?: any, headers?: any): Promise<ResponseStatusDTO>
  • Method to execute a request calling the driver's provider API.

    access

    public

    async

    Parameters

    • accessToken: string

      The access token attached as a Bearer token to the request.

    • endpointUri: string

      The endpoint URI of the driver's provider API.

    • method: HttpMethod = "GET"

      (Optional) The HTTP method used for the request, e.g. "GET". Defaults to "GET".

    • body: any = {}

      (Optional) The body of the request, as used with "POST" or "PUT" requests. Defaults to an empty object.

    • options: any = {}

      (Optional) An options object that is directly passed to axios before request execution. Defaults to an empty object.

    • headers: any = {}

    Returns Promise<ResponseStatusDTO>

    A promise containing the response and status in ResponseStatusDTO.

  • Helper method that extracts access- and refresh tokens, and expiration time of the access token from a HTTP response.

    A method overload can be implemented in extending OAuth driver classes to permit extracting additional fields, e.g. Strava shares an athlete object with initial access token requests.

    Note that this method automatically transforms UTC timestamps that use seconds since epoch into UTC timestamps that use milliseconds since epoch as defined in driver implementations.

    access

    protected

    Parameters

    • data: any

      The HTTP response data (parsed JSON object).

    Returns AccessTokenDTO

    A resulting AccessTokenDTO object.

  • Method to return the remote access token. The result is an access/refresh token pair. This method requires the use of an authorization code that is provided by the provider.

    These access tokens are always signed with the dApp's auth secret and expire after 1 hour (one hour).

    access

    public

    async

    Parameters

    • code: string

      The required code field value.

    • Optional data: string

      The required data field value.

    Returns Promise<AccessTokenDTO>

    A promise containing the result AccessTokenDTO.

  • getAuthorizeURL(extra: string): string
  • Method to transform an entity as described by the data provider API. Typically, this method is used to handle the transformation of remote objects (from data provider API) to internal objects in the backend runtime's database.

    e.g. This method is used to transform activity data as defined by the Strava API, into ActivityData as defined internally.

    Note that this implementation does not transform the remote data because this class corresponds to a generic OAuth implementation and as such must be compatible with any entity. For more details on specializations of this method, you may have a look at the code in StravaOAuthDriver.getEntityDefinition.

    access

    public

    Parameters

    Returns OAuthEntity

    A parsed entity object.

  • requestAccessToken(params: Record<string, string>): Promise<AccessTokenDTO>
  • Helper method that executes the actual access token request using a set of params parameters. The parameters set must contain the following fields:

    • client_id: Your Strava App's client identifier.
    • client_secret: Your Strava App's client secret.
    • grant_type: One of authorization_code or refresh_token.

      When executing a authorization request for the access token, the field authorization_code and code are obligatory as well. When executing a refresh request for the access token, it is the field refresh_token that is obligatory (no code).
    access

    protected

    async

    Parameters

    • params: Record<string, string>

      The parameters for the access token request.

    Returns Promise<AccessTokenDTO>

    A promise containing the resulting AccessTokenDTO object.

  • Method to return an updated access token from the driver's provider using a refresh token. The result is an access/refresh token pair.

    These access tokens are always signed with the dApp's auth secret and expire after 1 hour (one hour).

    access

    public

    async

    Parameters

    • refreshToken: string

      The user's refresh token.

    Returns Promise<AccessTokenDTO>

    A promise containing the result AccessTokenDTO.

Generated using TypeDoc