-
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.
Merge pull request #113 from atomicjolt/jb_enhance_lti_server
Add functionality to lti-server
- Loading branch information
Showing
54 changed files
with
1,676 additions
and
119 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -19,3 +19,4 @@ packages/atomic-fuel/libs | |
.vscode | ||
|
||
|
||
*.map |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1,33 +1,37 @@ | ||
# AtomicJolt LTI | ||
|
||
This is a collection of Javascript used by Atomic Jolt to assist in handling an LTI launch on the server. | ||
|
||
## Installation | ||
|
||
`npm i @atomicjolt/lti-server` | ||
|
||
## Usage | ||
|
||
For an example of how to use this library see https://github.com/atomicjolt/atomic-lti-worker | ||
|
||
The application code using this library must implement the LTI Launch in 3 phases, providing the server side code for each phase and returning and html response for each phase. Phases 1 and 3 will include a call to the client side javacript contained in this library. See the 1Edtech working group documentation for more information about the LTI standard: https://www.imsglobal.org/activity/learning-tools-interoperability. | ||
|
||
1. Open ID Connect initialization | ||
During this phase respond to the OIDC initialization request, attempt to write a state cookie and return and html page with a call to `InitOIDCLaunch` | ||
During this phase respond to the OIDC initialization request, attempt to write a state cookie and return and html page with a call to `initOIDCLaunch` from @atomicjolt/lti-client | ||
|
||
2. Redirect | ||
Server side validate the redirect and then return an HTML page capable of redirecting to the final LTI launch | ||
Server side validate the redirect and then return an HTML page capable of redirecting to the final LTI launch | ||
|
||
3. Handle the LTI launch. | ||
Validate the request including checking the nonce server side. Check for a valid state cookie and then return an HTML page with a script that calls `LtiLaunch` from this library. | ||
Validate the request including checking the nonce server side. Check for a valid state cookie and then return an HTML page with a script that calls `ltiLaunch` from @atomicjolt/lti-client. | ||
|
||
## Contributing | ||
|
||
Report any issues using Github | ||
|
||
Build package: | ||
`npm run build` | ||
`npm run build` | ||
|
||
Publish package: | ||
`npm publish --access public` | ||
`npm publish --access public` | ||
|
||
## License | ||
|
||
MIT | ||
This code is released as open source without any support or warranty. It is used by Atomic Jolt internally and is released in case someone finds it useful. |
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 |
---|---|---|
@@ -1,3 +1,22 @@ | ||
export * as LtiPlatform from './libs/platforms'; | ||
export * as LtiPlatform from './libs/platform_storage'; | ||
export * as LtiValidation from './libs/lti_validation'; | ||
export * as LtiOidc from './libs/oidc'; | ||
|
||
export { validateIdTokenContents } from './libs/lti_validation'; | ||
export { buildInit, validateNonce } from './libs/oidc'; | ||
export { getLtiStorageParams } from './libs/platform_storage'; | ||
|
||
export { | ||
OPEN_ID_COOKIE_PREFIX, | ||
OPEN_ID_STORAGE_COOKIE, | ||
ALLOWED_LAUNCH_TIME, | ||
} from './libs/constants'; | ||
export { ALGORITHM, signJwt, verifyJwt, getKid, getIss } from './libs/jwt'; | ||
export { generateKeySet, keySetsToJwks, fetchRemoteJwks, verifyJwtUsingJwks } from './libs/jwks'; | ||
export { TEST_ID_TOKEN, genJwt } from './tests/helper'; | ||
export { getDefaultToolConfiguration } from './libs/tool_configuration'; | ||
export { parseLinkHeader } from './libs/link_header'; | ||
export { requestServiceToken, ClientCredentialsError } from './libs/client_credentials'; | ||
export { createScore, sendScore } from './libs/scores'; | ||
export { listResults, showResult } from './libs/results'; | ||
export { listLineItems, showLineItem, createLineItem, updateLineItem } from './libs/line_items'; |
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,35 @@ | ||
import type { ClientAuthorizationRequest, ClientAuthorizationResponse } from '../../types'; | ||
|
||
export class ClientCredentialsError extends Error { } | ||
|
||
// Request a token from the platform that can be used in LTI Advantage requests | ||
export async function requestServiceToken(platformTokenUrl: string, token: string, scopes: string): Promise<ClientAuthorizationResponse> { | ||
const clientAuthorizationRequest: ClientAuthorizationRequest = { | ||
grant_type: 'client_credentials', | ||
client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer', | ||
scope: scopes, | ||
client_assertion: token, | ||
}; | ||
|
||
try { | ||
const formBody = new URLSearchParams(clientAuthorizationRequest).toString(); | ||
const response = await fetch(platformTokenUrl, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
body: formBody, | ||
}); | ||
|
||
if (response.status !== 200) { | ||
const text = await response.text(); | ||
if (text?.toLowerCase().indexOf('rate limit') >= 0) { | ||
throw new ClientCredentialsError('RateLimited'); | ||
} | ||
throw new ClientCredentialsError(`RequestFailed: ${text}`); | ||
} | ||
|
||
let clientAuth = await response.json() as ClientAuthorizationResponse; | ||
return clientAuth; | ||
} catch (error) { | ||
throw new ClientCredentialsError(`RequestFailed: ${error}`); | ||
} | ||
} |
Oops, something went wrong.