-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
give local copy of node-utils to ltiapi, log more, remove bad tests
- Loading branch information
1 parent
0a28c3a
commit e0d2545
Showing
99 changed files
with
3,227 additions
and
4,227 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
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
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
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
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
21 changes: 0 additions & 21 deletions
21
sourcecode/apis/lti/src/middlewares/__tests__/addContextToRequest.js
This file was deleted.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
sourcecode/apis/lti/src/node-utils/apiClients/auth/index.js
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,131 @@ | ||
import axios from 'axios'; | ||
import AwaitLock from 'await-lock'; | ||
import moment from 'moment'; | ||
import logger from '../../services/logger.js'; | ||
import * as errorReporting from '../../services/errorReporting.js'; | ||
import { verifyTokenAgainstAuth } from '../../services/auth.js'; | ||
|
||
let cachedToken = null; | ||
let jwksClients = {}; | ||
|
||
const createAuthAxios = (req, config) => async (options) => | ||
axios({ | ||
...options, | ||
url: `${config.url}${options.url}`, | ||
maxRedirects: 0, | ||
headers: { | ||
...options.headers, | ||
...errorReporting.getTraceHeaders(req), | ||
}, | ||
}); | ||
|
||
const authMutex = AwaitLock.default ? new AwaitLock.default() : new AwaitLock(); | ||
|
||
export default (req, config) => { | ||
const authAxios = createAuthAxios(req, config); | ||
|
||
const loginCallback = async (code, redirectUrl) => { | ||
const response = await authAxios({ | ||
url: `/oauth/token?client_id=${config.clientId}&code=${code}&redirect_uri=${redirectUrl}&grant_type=authorization_code`, | ||
method: 'GET', | ||
headers: { | ||
Authorization: `Basic ${Buffer.from( | ||
`${config.clientId}:${config.secret}` | ||
).toString('base64')}`, | ||
}, | ||
}); | ||
|
||
return response.data; | ||
}; | ||
|
||
const generateJwt = async (accessToken) => { | ||
const response = await authAxios({ | ||
url: `/v1/jwt/create`, | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
|
||
return response.data; | ||
}; | ||
|
||
const refreshJwt = async (accessToken) => { | ||
const response = await authAxios({ | ||
url: `/v2/jwt/refresh`, | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
|
||
return response.data; | ||
}; | ||
|
||
const identity = async (token) => { | ||
const response = await authAxios({ | ||
url: `/v1/identity?access_token=${token}`, | ||
method: 'GET', | ||
}); | ||
|
||
return response.data; | ||
}; | ||
|
||
const getOAuthToken = async (bypassCache = false) => { | ||
await authMutex.acquireAsync(); | ||
|
||
if ( | ||
!bypassCache && | ||
cachedToken && | ||
cachedToken.expiresAt.isAfter(moment()) | ||
) { | ||
authMutex.release(); | ||
return cachedToken.access_token; | ||
} | ||
|
||
logger.info( | ||
`Fetching new oauth server to server token from ${config.url}` | ||
); | ||
|
||
try { | ||
const authResponse = await axios({ | ||
url: `${config.url}/oauth/token`, | ||
method: 'POST', | ||
headers: { | ||
authorization: `Basic ${new Buffer( | ||
`${config.clientId}:${config.secret}` | ||
).toString('base64')}`, | ||
}, | ||
params: { grant_type: 'client_credentials' }, | ||
}); | ||
|
||
cachedToken = { | ||
...authResponse.data, | ||
expiresAt: moment().add( | ||
authResponse.data.expires_in - 60 * 2, // subtract 2 minutes in seconds to have a margin | ||
'seconds' | ||
), | ||
}; | ||
} catch (e) { | ||
authMutex.release(); | ||
throw e; | ||
} | ||
|
||
authMutex.release(); | ||
|
||
return cachedToken.access_token; | ||
}; | ||
|
||
return { | ||
loginCallback, | ||
identity, | ||
getOAuthToken, | ||
generateJwt, | ||
refreshJwt, | ||
verifyTokenAgainstAuth: verifyTokenAgainstAuth( | ||
jwksClients, | ||
`${config.url}/.well-known/jwks.json` | ||
), | ||
config, | ||
}; | ||
}; |
36 changes: 36 additions & 0 deletions
36
sourcecode/apis/lti/src/node-utils/apiClients/coreExternal/contentAuthor.js
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,36 @@ | ||
export default (core) => { | ||
const create = async (authorizationJwt, type, ltiExtraParameters) => { | ||
return ( | ||
await core({ | ||
url: `/v2/contentauthor/create${type ? `/${type}` : ''}`, | ||
method: 'POST', | ||
authorizationJwt, | ||
data: ltiExtraParameters, | ||
}) | ||
).data; | ||
}; | ||
|
||
const edit = async ( | ||
authorizationJwt, | ||
resourceId, | ||
translateToLanguage, | ||
launchPresentationLocale | ||
) => { | ||
return ( | ||
await core({ | ||
url: `/v2/contentauthor/edit/${resourceId}`, | ||
method: 'POST', | ||
authorizationJwt, | ||
data: { | ||
translateLanguage: translateToLanguage || undefined, | ||
launchPresentationLocale, | ||
}, | ||
}) | ||
).data; | ||
}; | ||
|
||
return { | ||
create, | ||
edit, | ||
}; | ||
}; |
50 changes: 50 additions & 0 deletions
50
sourcecode/apis/lti/src/node-utils/apiClients/coreExternal/index.js
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,50 @@ | ||
import axios from 'axios'; | ||
import recommendations from './recommendations.js'; | ||
import links from './links.js'; | ||
import preview from './preview.js'; | ||
import resourceFilters from './resourceFilters.js'; | ||
import contentAuthor from './contentAuthor.js'; | ||
import version from './version.js'; | ||
import resource from './resource.js'; | ||
import { exceptionTranslator } from '../../services/index.js'; | ||
import license from './license.js'; | ||
import info from './info.js'; | ||
import * as errorReporting from '../../services/errorReporting.js'; | ||
|
||
const coreAxios = (req, config) => async (options) => { | ||
try { | ||
let headers = { | ||
...options.headers, | ||
...errorReporting.getTraceHeaders(req), | ||
}; | ||
if (req.authorizationJwt) { | ||
headers.authorization = `Bearer ${req.authorizationJwt}`; | ||
} | ||
|
||
return await axios({ | ||
...options, | ||
url: `${config.url}${options.url}`, | ||
headers, | ||
maxRedirects: 0, | ||
}); | ||
} catch (e) { | ||
exceptionTranslator(e, 'Core external API'); | ||
} | ||
}; | ||
|
||
export default (req, config) => { | ||
const core = coreAxios(req, config); | ||
|
||
return { | ||
recommendations: recommendations(core), | ||
links: links(core), | ||
preview: preview(core), | ||
resourceFilters: resourceFilters(core), | ||
contentAuthor: contentAuthor(core), | ||
version: version(core), | ||
resource: resource(core), | ||
license: license(core), | ||
info: info(core), | ||
config, | ||
}; | ||
}; |
Oops, something went wrong.