-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d6531b
commit 783e603
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ucts/jbrowse-react-linear-genome-view/stories/UsingInternetAccounts.stories.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Meta, Story, Canvas } from '@storybook/addon-docs' | ||
import { isArrayLike } from 'lodash' | ||
|
||
<Meta title="Using InternetAccounts" /> | ||
|
||
## Using InternetAccounts | ||
|
||
Starting with v2.2.1 of `@jbrowse/react-linear-genome-view`, developers can use | ||
JBrowse's InternetAccounts in the component. | ||
|
||
Before using InternetAccounts, make sure they are what you need for your | ||
application. InternetAccounts in JBrowse Web are generally used for accessing | ||
controlled files, e.g. Google Drive, Dropbox, and other password-protected | ||
files. Often it will be better to handle this type of functionality in your app | ||
and then run `@jbrowse/react-linear-genome-view` in an part of your app that has | ||
already been authenticated. In fact, JBrowse's DropboxOAuthInternetAccount and | ||
GoogleDriveOAuthInternetAccount will not work as-is because | ||
`@jbrowse/react-linear-genome-view` doesn't have the app-level control needed to | ||
properly execute an OAuth 2.0 login flow. | ||
|
||
There are some instances where InternetAccounts could be useful, though. For | ||
example, you can use a custom InterentAccount to override the `fetch` behavior | ||
of a particular track, allowing you to customize where and how the data is | ||
retrieved. | ||
|
||
InternetAccount configurations are passed to `createViewState` like this: | ||
|
||
```js | ||
import { | ||
createViewState, | ||
loadPlugins, | ||
JBrowseLinearGenomeView, | ||
} from '@jbrowse/react-linear-genome-view' | ||
import makeWorkerInstance from '@jbrowse/react-linear-genome-view/esm/makeWorkerInstance' | ||
|
||
function YourApp() { | ||
const state = createViewState({ | ||
assembly, | ||
tracks, | ||
location: 'ctgA:1105..1221', | ||
internetAccounts: [ | ||
{ | ||
type: 'ExternalTokenInternetAccount', | ||
internetAccountId: 'manualGoogleEntry', | ||
name: 'Google Drive Manual Token Entry', | ||
description: 'Manually enter a token to access Google Drive files', | ||
tokenType: 'Bearer', | ||
}, | ||
], | ||
}) | ||
|
||
return <JBrowseLinearGenomeView viewState={state} /> | ||
} | ||
``` | ||
|
||
Then any file location in your tracks that specifies an `internetAccountId` of | ||
"manualGoogleEntry" will use the specified InternetAccount. The above example | ||
lets the user manually enter a token already retrieved elsewhere. An | ||
"Authorization" header is then set on any request to that resource with a value | ||
of `Bearer <token>`. | ||
|
||
<Canvas withSource="open"> | ||
<Story id="linear-view--with-internet-accounts" /> | ||
</Canvas> |