# BaseInternetAccountModel

Auto-generated from the @jbrowse/mobx-state-tree model in the source — see the [developer guide](https://jbrowse.org/jb2/docs/developer_guide/) for concepts. Built into JBrowse core. [View source](https://github.com/GMOD/jbrowse-components/blob/main/packages/core/src/pluggableElementTypes/models/InternetAccountModel.ts).

Adds a token header to each request for a file on one of the account's
domains, keeping the token in `sessionStorage`. Every internet account type
builds on this model.

## Properties

| Member | Description |
| --- | --- |
| **id**<br><code>id: ElementId</code> |  |
| **type**<br><code>type: types.string</code> |  |
| **configuration**<br><code>configuration: ConfigurationReference(BaseInternetAccountConfig)</code> |  |

## Getters

| Member | Description |
| --- | --- |
| **name**<br><code>string</code> |  |
| **description**<br><code>string</code> |  |
| **internetAccountId**<br><code>string</code> |  |
| **authHeader**<br><code>string</code> |  |
| **tokenType**<br><code>string</code> |  |
| **domains**<br><code>string[]</code> |  |
| **toggleContents**<br><code>ReactNode</code> | Can use this to customize what is displayed in fileSelector's toggle box |
| **selectorLabel**<br><code>string &#124; undefined</code> | Can use this to add a label to the UrlChooser |
| **showInFileSelector**<br><code>boolean</code> | Whether the fileSelector offers this account as a source to pick. Turn it off for an account that only ever matches by domain and has nothing of its own to enter — HTTP Basic, whose ephemeral per-origin accounts would otherwise pile up as toggles nobody asked for. |
| **tokenKey**<br><code>string</code> | The key used to store this internetAccount's token in sessionStorage |

## Methods

| Member | Description |
| --- | --- |
| **handlesLocation**<br><code>(location: UriLocation) =&gt; boolean</code> | Determine whether this internetAccount provides credentials for a URL |

## Actions

| Member | Description |
| --- | --- |
| **getTokenFromUser**<br><code>(_resolve: (token: string) =&gt; void, _reject: (error: Error) =&gt; void) =&gt; void</code> | Must be implemented by a model extending or composing this one. Pass the user's token to `resolve`. |
| **storeToken**<br><code>(token: string) =&gt; void</code> |  |
| **retrieveToken**<br><code>() =&gt; string &#124; undefined</code> |  |
| **validateToken**<br><code>(token: string, _loc: UriLocation) =&gt; Promise&lt;string&gt;</code> | This can be used by an internetAccount to validate a token works before it is used. This is run when preAuthorizationInformation is requested, so it can be used to check that a token is valid before sending it to a worker thread. It expects the token to be returned so that this action can also be used to generate a new token (e.g. by using a refresh token) if the original one was invalid. Should throw an error if a token is invalid. |
| **removeToken**<br><code>() =&gt; void</code> | Clears the stored token. Also drops the in-memory cached promise so a subsequent `getToken` re-prompts / re-derives rather than handing back the token that was just invalidated. |
| **getToken**<br><code>(location?: UriLocation &#124; undefined) =&gt; Promise&lt;string&gt;</code> | Try to get the token from the location pre-auth, from local storage, or from a previously cached promise. If token is not available, uses `getTokenFromUser`. |
| **addAuthHeaderToInit**<br><code>(init?: RequestInit &#124; undefined, token?: string &#124; undefined) =&gt; { headers: Headers; body?: BodyInit &#124; null &#124; undefined; cache?: RequestCache &#124; undefined; credentials?: RequestCredentials &#124; undefined; integrity?: string &#124; undefined; keepalive?: boolean &#124; undefined; method?: string &#124; undefined; mode?: RequestMode &#124; undefined; priority?: RequestPriority &#124; undefined; redirect?: RequestRedirect &#124; undefined; referrer?: string &#124; undefined; referrerPolicy?: ReferrerPolicy &#124; undefined; signal?: AbortSignal &#124; null &#124; undefined; window?: null &#124; undefined; }</code> |  |
| **fetchWithToken**<br><code>(loc: UriLocation &#124; undefined, run: (token: string) =&gt; Promise&lt;Response&gt;) =&gt; Promise&lt;Response&gt;</code> | Run a request with the current token and, only if it comes back 401, put the token through `validateToken` and run it exactly once more. This is how every account's fetcher reaches a resource. |
| **getPreAuthorizationInformation**<br><code>(location: UriLocation) =&gt; Promise&lt;{ internetAccountType: string; authInfo: { token: string; configuration: ModelSnapshotType&lt;Record&lt;string, any&gt;&gt;; }; }&gt;</code> | Gets the token and returns it along with the information needed to create a new internetAccount. |
| **getFetcher**<br><code>(loc?: UriLocation &#124; undefined) =&gt; (input: RequestInfo, init?: RequestInit &#124; undefined) =&gt; Promise&lt;Response&gt;</code> | Get a fetch method that will add any needed authentication headers to the request before sending it. If location is provided, it will be checked to see if it includes a token in it pre-auth information. |
| **openLocation**<br><code>(location: UriLocation) =&gt; RemoteFileWithRangeCache</code> | Gets a filehandle that uses a fetch that adds auth headers |

