Skip to content

Commit afdfcf9

Browse files
committed
Updated documentation
1 parent e813dbb commit afdfcf9

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

docs/dropbox-googledrive-solid.md

+58-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ Console](https://console.developers.google.com/flows/enableapi?apiid=drive).
9696
## Solid
9797

9898
An authentication URL must always have been set on the Solid backend before
99-
calling `connect()`. You can do so by calling `setAuthURL()` first.
99+
calling `connect()`. You can do so by calling `remoteStorage.solid.setAuthURL()`
100+
first.
100101

101102
The connect widget accepts a list of authentication URLs as configuration
102103
and automatically sets it on the Solid backend when selected.
@@ -112,3 +113,59 @@ from the [Inrupt](https://docs.inrupt.com/developer-tools/javascript/client-libr
112113
Solid library. It can be accessed by calling `remoteStorage.solid.getSession()`
113114
only after the backend is connected.
114115
:::
116+
117+
### Conneting to Solid without the widget
118+
119+
[Solid](https://solidproject.org/) is an open standard for structuring data,
120+
digital identities, and applications on the Web.
121+
122+
In order to connect to a Solid pod i.e. storage, the first step is to
123+
authenticate with a Solid Identity Provider which is achieved by first calling
124+
`solid.setAuthURL()` and then calling `solid.connect()`.
125+
126+
Solid supports multiple storage pods for each user. So after successfully
127+
authenticating, you'll need to get a list of available pods for that user and
128+
pick one to be used by the remote storage library. A successful authentication
129+
process fires the `pod-not-selected` event after calling connect. Upon
130+
receiving this event you must call `solid.getPodURLs()` to get a list of
131+
available pods. There is usually only one pod per user but it can be any number
132+
starting from zero.
133+
134+
Call `solid.setPodURL()` after deciding which pod to use. The widget
135+
automatically selects the pod if there is only one available. Prompts the user
136+
if there are multiple available and shows an error if there is none. After
137+
setting the pod URL, you'll immediately receive the `connected` event.
138+
139+
::: info
140+
If the connection process has reached the `pod-not-selected` step, the progress
141+
is saved and the next time the page refreshes, you'll receive event and can
142+
continue from there.
143+
:::
144+
145+
Calling `connect()` always ends up in redirecting the page to the identity
146+
provider website. So does future page loads after a successful authentication.
147+
Upon returning, the response bears if the user still has access. This means
148+
that the page never loads with the connected state. It'll take a few moments
149+
and if everything is fine, `connected` is an event that is always fired.
150+
151+
A basic code that doesn't use the widget will look like this:
152+
```js
153+
const connectTask = setTimeout(() => {
154+
remoteStorage.solid.setAuthURL('solid-identity-provider-url'); // i.e. https://login.inrupt.com
155+
remoteStorage.solid.connect();
156+
// Calling 'connect()' will immediately redirect to the identity provider website.
157+
}, 1000);
158+
remoteStorage.on('pod-not-selected', () => {
159+
clearTimeout(connectTask);
160+
const podURLs = remoteStorage.solid.getPodURLs();
161+
// Choose one. Maybe there is even 0?
162+
remoteStorage.solid.setPodURL(podURLs[0]);
163+
// That's it. 'connected' is fired immediately.
164+
};
165+
remoteStorage.on('connected', () => {
166+
// We are connected.
167+
clearTimeout(connectTask);
168+
// We arrive here either through calling 'setPodURL' on the `pod-not-selected` event or
169+
// on page getting loaded.
170+
});
171+
```

src/interfaces/configObserver.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* @interface ConfigObserver
3+
*
4+
* This interface is used by the ConfingStorage inside the Solid backend. The
5+
* purpose is to be notified when the Solid session information need to be
6+
* stored.
7+
*/
18
export interface ConfigObserver {
29
onConfigChanged(config: string): void;
310
}

src/solidStorage.ts

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import {
33
} from "@inrupt/solid-client-authn-browser";
44
import { ConfigObserver } from "./interfaces/configObserver";
55

6+
/**
7+
* @class BrowserStorage
8+
*
9+
* Mirror of BrowserStorage that is defined (but not exported) in the Inrupt
10+
* library.
11+
*/
612
class BrowserStorage implements IStorage {
713
get storage(): typeof window.localStorage {
814
return window.localStorage;
@@ -21,6 +27,12 @@ class BrowserStorage implements IStorage {
2127
}
2228
}
2329

30+
/**
31+
* @class ConfigStorage
32+
*
33+
* An implementation for the Inrupt's IStorage that bypasses storing of the
34+
* session information to the ConfigObserver i.e. Solid backend.
35+
*/
2436
export default class ConfigStorage implements IStorage {
2537
private browserStorage: BrowserStorage = new BrowserStorage();
2638
private config: string;
@@ -30,6 +42,14 @@ export default class ConfigStorage implements IStorage {
3042
this.observer = observer;
3143
}
3244

45+
/**
46+
* Information specific to the user session are stored using this prefix.
47+
* Caution: This is a bit hacky. Inrupt stores different sorts of data and
48+
* does not differentiate between them and the session specific one. Saving
49+
* all that as the backend config is expensive and invalid. This key
50+
* constant is taken from Inrupt's private code here:
51+
* https://github.com/inrupt/solid-client-authn-js/blob/a34357598cc218be116e38f66a983e391dc1d6b2/packages/core/src/storage/StorageUtility.ts#L150
52+
*/
3353
private isConfigKey(key: string): boolean {
3454
return key.startsWith('solidClientAuthenticationUser');
3555
}

0 commit comments

Comments
 (0)