Skip to content

Commit bef5a91

Browse files
Copilotjeswr
andauthored
fix: use optional SOLID_RESOURCE_URL for authenticated fetch example (#16)
* Initial plan * fix: add optional SOLID_RESOURCE_URL env var for the resource to fetch Co-authored-by: jeswr <63333554+jeswr@users.noreply.github.com> * Apply suggestions from code review --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jeswr <63333554+jeswr@users.noreply.github.com>
1 parent 7259b99 commit bef5a91

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

docs/guides/authenticating_with_a_script.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { Session } from '@inrupt/solid-client-authn-node';
7373
const CLIENT_ID = process.env.SOLID_CLIENT_ID;
7474
const CLIENT_SECRET = process.env.SOLID_CLIENT_SECRET;
7575
const OIDC_ISSUER = process.env.SOLID_OIDC_ISSUER; // Your authorization server URL (sometimes called IdP, sometimes same as your Solid server URL)
76+
const RESOURCE_URL = process.env.SOLID_RESOURCE_URL; // URL of the protected resource to fetch (optional)
7677

7778
async function main() {
7879
// Create a new session and log in
@@ -90,8 +91,9 @@ async function main() {
9091

9192
// session.fetch works just like the standard fetch API,
9293
// but automatically includes authentication headers.
93-
const response = await session.fetch(session.info.webId);
94-
console.log(`GET ${session.info.webId}${response.status}`);
94+
const resourceUrl = RESOURCE_URL ?? session.info.webId;
95+
const response = await session.fetch(resourceUrl);
96+
console.log(`GET ${resourceUrl}${response.status}`);
9597
console.log(await response.text());
9698

9799
// Always log out when done
@@ -102,14 +104,15 @@ async function main() {
102104
main().catch(console.error);
103105
```
104106
105-
Run the script, passing your credentials and authorization server URL (sometimes same as Solid server URL) as environment variables.
107+
Run the script, passing your credentials, authorization server URL (sometimes same as Solid server URL), and optionally the URL of the protected resource you want to fetch as environment variables.
106108
107109
On **Linux / macOS** (Bash):
108110
109111
```bash
110112
SOLID_CLIENT_ID="your-client-id" \
111113
SOLID_CLIENT_SECRET="your-client-secret" \
112114
SOLID_OIDC_ISSUER="http://localhost:3000" \
115+
SOLID_RESOURCE_URL="http://localhost:3000/your-pod/private-resource" \
113116
node index.js
114117
```
115118
@@ -119,12 +122,13 @@ On **Windows** (PowerShell):
119122
$env:SOLID_CLIENT_ID="your-client-id"
120123
$env:SOLID_CLIENT_SECRET="your-client-secret"
121124
$env:SOLID_OIDC_ISSUER="http://localhost:3000"
125+
$env:SOLID_RESOURCE_URL="http://localhost:3000/your-pod/private-resource"
122126
node index.js
123127
```
124128
125-
Replace `http://localhost:3000` with the URL of your Solid server (for example, `https://solidcommunity.net` or `https://login.inrupt.com`).
129+
Replace `http://localhost:3000` with the URL of your authorization server (for example, `https://solidcommunity.net` or `https://login.inrupt.com`), and set `SOLID_RESOURCE_URL` to the URL of the private resource you want to access. If `SOLID_RESOURCE_URL` is omitted, the script falls back to fetching your WebID profile document.
126130

127-
You should see your profile document printed to the console.
131+
You should see the contents of the resource printed to the console.
128132

129133
## Tips
130134

0 commit comments

Comments
 (0)