# All files / src/auth appConfig.ts

100% Statements 11/11
100% Branches 6/6
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    1x
    1x

    1x

    41x
    41x
    41x
    41x
    41x
    41x

    6x

    6x

    import { DEFAULT_SCOPE, DEFAULT_BLOCKSTACK_HOST, AuthScope } from './authConstants'
    import { getGlobalObject } from '../utils'

    /**
     * Configuration data for the current app.
     *
     * On browser platforms, creating an instance of this
     * class without any arguments will use
     * `window.location.origin` as the app domain.
     * On non-browser platforms, you need to
     * specify an app domain as the second argument.
     *
     */
    export class AppConfig {
      /**
       * Blockstack apps are uniquely identified by their app domain.
       *
       */
      appDomain: string

      /**
       * An array of string representing permissions requested by the app.
       *
       */
      scopes: Array<AuthScope | string>

      /**
       * Path on app domain to redirect users to after authentication. The
       * authentication response token will be postpended in a query.
       *
       */
      redirectPath: string

      /**
       * Path relative to app domain of app's manifest file.
       *
       * This file needs to have CORS headers set so that it can be fetched
       * from any origin. Typically this means return the header `Access-Control-Allow-Origin: *`.
       *
       */
      manifestPath: string

      /**
       * The URL of Blockstack core node to use for this app. If this is
       * `null`, the core node specified by the user or default core node
       * will be used.
       *
       */
      coreNode: string

      /**
       * The URL of a web-based Blockstack Authenticator to use in the event
       * the user doesn't have Blockstack installed on their machine. If this
       * is not specified, the current default in this library will be used.
       *
       */
      authenticatorURL?: string

      /**
       * @param {Array<string>} scopes - permissions this app is requesting
       * @param {string} appDomain - the app domain
       * @param {string} redirectPath - path on app domain to redirect users to after authentication
       * @param {string} manifestPath - path relative to app domain of app's manifest file
       * @param {string} coreNode - override the default or user selected core node
       * @param {string} authenticatorURL - the web-based fall back authenticator
       * ([[DEFAULT_BLOCKSTACK_HOST]])
       */
      constructor(scopes: Array<string> = DEFAULT_SCOPE.slice(),
                  appDomain: string = getGlobalObject('location', { returnEmptyObject: true }).origin,
                  redirectPath: string = '',
                  manifestPath: string = '/manifest.json',
                  coreNode: string | null = null,
                  authenticatorURL: string = DEFAULT_BLOCKSTACK_HOST) {
        this.appDomain = appDomain
        this.scopes = scopes
        this.redirectPath = redirectPath
        this.manifestPath = manifestPath
        this.coreNode = coreNode
        this.authenticatorURL = authenticatorURL
      }

      /**
       * The location to which the authenticator should
       * redirect the user.
       * @returns {string} - URI
       */
      redirectURI(): string {
        return `${this.appDomain}${this.redirectPath}`
      }

      /**
       * The location of the app's manifest file.
       * @returns {string} - URI
       */
      manifestURI(): string {
        return `${this.appDomain}${this.manifestPath}`
      }
    }