-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: add code from
serlo-editor-for-edusharing
and reorganize
- Loading branch information
1 parent
5c6ff65
commit 2d802e1
Showing
20 changed files
with
2,536 additions
and
120 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# .env - Should not be added because it contains private keys used for encryption | ||
.env | ||
*.env | ||
|
||
# Logs | ||
logs | ||
|
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
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
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
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
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
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,16 @@ | ||
import jwt from 'jsonwebtoken' | ||
|
||
export function createAccessToken( | ||
editorMode: 'read' | 'write', | ||
entityId: number, | ||
signingKey: string | ||
) { | ||
return jwt.sign( | ||
{ | ||
entityId: entityId, | ||
accessRight: editorMode, | ||
}, | ||
signingKey, // Reuse the symmetric HS256 key used by ltijs to sign ltik and database entries | ||
{ expiresIn: '3 days' } | ||
) | ||
} |
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,85 @@ | ||
import type { Response } from 'express' | ||
import * as t from 'io-ts' | ||
|
||
export function createAutoFromResponse({ | ||
res, | ||
method = 'GET', | ||
targetUrl, | ||
params, | ||
}: { | ||
res: Response | ||
method?: 'GET' | 'POST' | ||
targetUrl: string | ||
params: Record<string, string> | ||
}) { | ||
const escapedTargetUrl = escapeHTML(targetUrl) | ||
const formDataHtml = Object.entries(params) | ||
.map(([name, value]) => { | ||
const escapedValue = escapeHTML(value) | ||
return `<input type="hidden" name="${name}" value="${escapedValue}" />` | ||
}) | ||
.join('\n') | ||
|
||
res.setHeader('Content-Type', 'text/html') | ||
res.send( | ||
`<!DOCTYPE html> | ||
<html> | ||
<head><title>Redirect to ${escapedTargetUrl}</title></head> | ||
<body> | ||
<form id="form" action="${escapedTargetUrl}" method="${method}"> | ||
${formDataHtml} | ||
</form> | ||
<script type="text/javascript"> | ||
document.getElementById("form").submit(); | ||
</script> | ||
</body> | ||
</html> | ||
`.trim() | ||
) | ||
res.end() | ||
} | ||
|
||
function escapeHTML(text: string): string { | ||
return text | ||
.replaceAll('&', '&') | ||
.replaceAll('"', '"') | ||
.replaceAll('<', '<') | ||
.replaceAll('>', '>') | ||
} | ||
|
||
export const EdusharingAssetDecoder = t.type({ | ||
nodeId: t.string, | ||
repositoryId: t.string, | ||
}) | ||
|
||
export const JwtDeepflowResponseDecoder = t.type({ | ||
'https://purl.imsglobal.org/spec/lti-dl/claim/content_items': t.array( | ||
t.type({ | ||
custom: EdusharingAssetDecoder, | ||
}) | ||
), | ||
}) | ||
|
||
export const DeeplinkNonce = t.type({ nonce: t.string }) | ||
export const DeeplinkLoginData = t.type({ | ||
dataToken: t.string, | ||
nodeId: t.string, | ||
user: t.string, | ||
}) | ||
|
||
// Define type for the LTI claim https://purl.imsglobal.org/spec/lti/claim/custom | ||
// Partial contains optional properties. | ||
// TODO: rename to not confuse it with other custom types | ||
export const LtiCustomType = t.intersection([ | ||
t.type({ | ||
getContentApiUrl: t.string, | ||
appId: t.string, | ||
}), | ||
DeeplinkLoginData, | ||
t.partial({ | ||
fileName: t.string, | ||
/** Is set when editor was opened in edit mode */ | ||
postContentApiUrl: t.string, | ||
version: t.string, | ||
}), | ||
]) |
Oops, something went wrong.