FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScriptSolidServer/auth.js at gh-pages · JavaScriptSolidServer/JavaScriptSolidServer · GitHub
JavaScriptSolidServer
JavaScriptSolidServer
Repository navigation
Code
Issues
164
(164)
Pull requests
14
(14)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScriptSolidServer
/
auth.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (48 loc) · 2.04 KB
Breadcrumbs
JavaScriptSolidServer
/
auth.js
Copy path
File metadata and controls
50 lines (48 loc) · 2.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/**
* Public authentication api (#584).
*
* The stable import path for applications that authenticate their own
* traffic — app plugins mounted via `appPaths` (#582), external Fastify
* compositions, MCP-adjacent tooling. Everything in src/ is internal and
* may move; this file is the contract.
*
* import { getAgent } from 'javascript-solid-server/auth.js';
*
* const agent = await getAgent(request); // string | null
*
* Covers every credential scheme the server itself accepts, uniformly:
* IdP-issued Bearer tokens, Solid-OIDC DPoP, Nostr NIP-98 signatures,
* LWS10-CID, and WebID-TLS client certificates.
* The returned identifier is usually an HTTP(S) WebID;
* for NIP-98 it can be a `did:nostr:...` DID when no WebID mapping
* exists — DID agents are first-class here, which is why this is
* getAgent and not getWebId. Key your app's users on the string.
*
* Authentication only — deliberately not authorization:
* apps under an appPaths prefix own their own permissioning (WAC stays
* out of their jurisdiction, and `request.webId` is never set there).
*
* This is the pre-loader shape of the seam; when the plugin loader (#206)
* lands, `api.auth.getAgent` will be this same function handed to
* `activate(api)`.
*/
import
{
getWebIdFromRequestAsync
}
from
'./src/auth/token.js'
;
/**
* Resolve the authenticated agent of a request.
*
@param
{
object
} request - a Fastify request. Pass the real request object:
* Bearer verification only reads `headers`, but DPoP (Solid-OIDC),
* NIP-98 and LWS-CID verification also read `method`, `url`, `protocol`
* and `hostname` to check what the credential was signed over.
*
@returns
{
Promise<string|null>
} the verified agent identifier — an
* HTTP(S) WebID, or a `did:nostr:` DID for NIP-98 agents without a
* WebID mapping — or null when anonymous / invalid. Never throws on
* bad credentials.
*/
export
async
function
getAgent
(
request
)
{
try
{
const
{
webId
}
=
await
getWebIdFromRequestAsync
(
request
)
;
return
webId
||
null
;
}
catch
{
return
null
;
}
}
Back
|
FazBrowse Home
|
New Git URL