Skip to content

Commit 50ea82d

Browse files
Bump to v0.0.18 - Fix mashlib browser login and RDF content types
- Add RDF file extensions to content type detection (.ttl, .n3, .nt, .rdf, .nq, .trig) - Update isRdfContentType() to recognize all RDF MIME types - Fix IdP login to do proper HTTP redirects for browsers while keeping JSON response for CTH
1 parent a62c87d commit 50ea82d

3 files changed

Lines changed: 32 additions & 15 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "javascript-solid-server",
3-
"version": "0.0.17",
3+
"version": "0.0.18",
44
"description": "A minimal, fast Solid server",
55
"main": "src/index.js",
66
"type": "module",

src/idp/interactions.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,22 @@ export async function handleLogin(request, reply, provider) {
118118

119119
request.log.info({ accountId: account.id, uid }, 'Login successful');
120120

121-
// For CTH compatibility, we need to return a response that CTH can handle.
122-
// CTH expects either:
123-
// 1. A redirect it can follow (but Java HttpClient follows to final destination which fails)
124-
// 2. A 200 response with "location" in body (CSS v3+ style)
125-
//
126-
// We use interactionResult to get the redirect URL, then save it and return JSON
127-
128-
// Save the login result to the interaction for programmatic clients
129-
// This allows the auth endpoint to continue the flow when resumed
121+
// Detect if this is a browser (wants HTML/redirect) or programmatic client (wants JSON)
122+
const acceptHeader = request.headers.accept || '';
123+
const wantsBrowserRedirect = acceptHeader.includes('text/html') && !acceptHeader.includes('application/json');
124+
125+
// Save the login result to the interaction
130126
interaction.result = result;
131127
await interaction.save(interaction.exp - Math.floor(Date.now() / 1000));
132128

133-
// For CTH and programmatic clients: use interactionFinished with hijacked response
134-
// to properly complete the interaction while returning JSON
129+
// For browsers (mashlib, etc): do a proper HTTP redirect
130+
if (wantsBrowserRedirect) {
131+
reply.hijack();
132+
return provider.interactionFinished(request.raw, reply.raw, result, { mergeWithLastSubmission: false });
133+
}
134+
135+
// For CTH and programmatic clients: return JSON with location
136+
// CTH expects a 200 response with "location" in body (CSS v3+ style)
135137
try {
136138
reply.hijack();
137139

@@ -188,7 +190,6 @@ export async function handleLogin(request, reply, provider) {
188190
request.log.warn({ err: err.message, errName: err.name, uid }, 'interactionFinished failed, using fallback');
189191

190192
// Fallback: return the redirect URL for manual following
191-
// The interaction result is already saved above
192193
const redirectTo = `/idp/auth/${uid}`;
193194
return reply
194195
.code(200)

src/utils/url.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ export function getContentType(filePath) {
120120
'.jpeg': 'image/jpeg',
121121
'.gif': 'image/gif',
122122
'.svg': 'image/svg+xml',
123-
'.pdf': 'application/pdf'
123+
'.pdf': 'application/pdf',
124+
'.ttl': 'text/turtle',
125+
'.n3': 'text/n3',
126+
'.nt': 'application/n-triples',
127+
'.rdf': 'application/rdf+xml',
128+
'.nq': 'application/n-quads',
129+
'.trig': 'application/trig'
124130
};
125131
return types[ext] || 'application/octet-stream';
126132
}
@@ -131,5 +137,15 @@ export function getContentType(filePath) {
131137
* @returns {boolean}
132138
*/
133139
export function isRdfContentType(contentType) {
134-
return contentType === 'application/ld+json' || contentType === 'application/json';
140+
const rdfTypes = [
141+
'application/ld+json',
142+
'application/json',
143+
'text/turtle',
144+
'text/n3',
145+
'application/n-triples',
146+
'application/rdf+xml',
147+
'application/n-quads',
148+
'application/trig'
149+
];
150+
return rdfTypes.includes(contentType);
135151
}

0 commit comments

Comments
 (0)