caccl-authorizer
Advanced tools
Comparing version 1.0.43 to 1.0.44
29
index.js
@@ -6,2 +6,3 @@ const fs = require('fs'); | ||
const API = require('caccl-api'); | ||
const getScopes = require('caccl-api/getScopes'); | ||
const CACCLError = require('caccl-error'); | ||
@@ -110,2 +111,7 @@ const sendRequest = require('caccl-send-request'); | ||
* launchPath and has not launched via LTI, they will be given an error | ||
* @param {object[]} [scopes] - list of caccl-api functions | ||
* (e.g. api.course.listStudents), caccl-api endpoint categories | ||
* (e.g. api.course), or scope strings (e.g. url:GET|/api/v1/courses). You | ||
* may mix and match any of the types above. These scopes will be included | ||
* in all authorization requests | ||
*/ | ||
@@ -141,2 +147,15 @@ module.exports = (config) => { | ||
// Initialize scopes | ||
let scopeAuthPageQueryAddon = ''; | ||
let scopesParam; | ||
if (config.scopes) { | ||
const scopeLists = config.scopes.map((scope) => { | ||
return getScopes(scope); | ||
}); | ||
const scopes = [].concat(...scopeLists); | ||
const scopeString = scopes.join(' '); | ||
scopeAuthPageQueryAddon = `&scopes=${encodeURIComponent(scopeString)}`; | ||
scopesParam = scopes; | ||
} | ||
// Initialize the default authorized redirect path | ||
@@ -192,6 +211,7 @@ const defaultAuthorizedRedirect = config.defaultAuthorizedRedirect || '/'; | ||
params: { | ||
scopesParam, | ||
grant_type: 'refresh_token', | ||
refresh_token: refreshToken, | ||
client_id: config.developerCredentials.client_id, | ||
client_secret: config.developerCredentials.client_secret, | ||
refresh_token: refreshToken, | ||
}, | ||
@@ -363,3 +383,3 @@ }) | ||
// Refresh failed. Redirect to start authorization process | ||
const authURL = 'https://' + canvasHost + '/login/oauth2/auth?client_id=' + config.developerCredentials.client_id + '&response_type=code&redirect_uri=https://' + req.headers.host + launchPath + '&state=' + nextPath; | ||
const authURL = `https://${canvasHost}/login/oauth2/auth?client_id=${config.developerCredentials.client_id}&response_type=code&redirect_uri=https://${req.hostname}${launchPath}&state=${nextPath}${scopeAuthPageQueryAddon}`; | ||
return res.redirect(authURL); | ||
@@ -434,7 +454,8 @@ }); | ||
params: { | ||
code, | ||
scopesParam, | ||
grant_type: 'authorization_code', | ||
code, | ||
client_id: config.developerCredentials.client_id, | ||
client_secret: config.developerCredentials.client_secret, | ||
redirect_uri: 'https://' + req.headers.host + launchPath, | ||
redirect_uri: `https://${req.hostname}${launchPath}`, | ||
}, | ||
@@ -441,0 +462,0 @@ ignoreSSLIssues: canvasHost.startsWith('localhost'), |
{ | ||
"name": "caccl-authorizer", | ||
"version": "1.0.43", | ||
"version": "1.0.44", | ||
"description": "Acquires Canvas tokens through via OAuth, stores refresh tokens, and refreshes access tokens when they expire.", | ||
@@ -32,8 +32,8 @@ "main": "index.js", | ||
"body-parser": "^1.19.0", | ||
"caccl": "^1.0.125", | ||
"caccl": "^1.0.126", | ||
"caccl-canvas-partial-simulator": "^1.0.36", | ||
"dce-selenium": "^1.0.51", | ||
"dce-selenium": "^1.0.52", | ||
"eslint": "^5.16.0", | ||
"eslint-config-airbnb": "^17.1.1", | ||
"eslint-plugin-cypress": "^2.7.0", | ||
"eslint-plugin-cypress": "^2.8.1", | ||
"eslint-plugin-import": "^2.19.1", | ||
@@ -50,3 +50,3 @@ "eslint-plugin-jsx-a11y": "^6.2.3", | ||
"dependencies": { | ||
"caccl-api": "^1.0.51", | ||
"caccl-api": "^1.0.53", | ||
"caccl-error": "^1.0.3", | ||
@@ -53,0 +53,0 @@ "caccl-lti": "^1.0.21", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88228
2035
Updatedcaccl-api@^1.0.53