function getHeaderFromToken(token) { const decodedToken = jwt.decode(token, { complete: true }); if (!decodedToken) { throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, `provided token does not decode as JWT`); } return decodedToken.header; }
/** * Get the session data for an Upload Server URL. */ async function getSession (url) { const token = await loadToken(url) if (!token) return null const header = jwt.decode(token) if (!header) return null const now = Math.floor(Date.now() / 1000) if (header.exp <= now) return null return header }
async function getSessions () { let tokens = {} try { const data = await readFile(credentialsPath) tokens = JSON.parse(data) } catch (err) {} const sessions = {} Object.keys(tokens).forEach((url) => { sessions[url] = validateToken(tokens[url]) ? jwt.decode(tokens[url]) : null }) return sessions }
/** * Check that a JWT has not expired. */ function validateToken (token) { const header = jwt.decode(token) const now = Math.floor(Date.now() / 1000) return header && header.exp > now }
async addAuthToken(authToken, config) { if (!config) { config = await this.loadConfig(); } const payload = jwt.decode(authToken); if (!payload || !payload.url) { // eslint-disable-next-line no-throw-literal throw 'Malformed Cube Cloud token'; } config.auth = config.auth || {}; config.auth[payload.url] = { auth: authToken }; await this.writeConfig(config); return config; }
async deployAuth(url) { if (process.env.CUBE_CLOUD_DEPLOY_AUTH) { const payload = jwt.decode(process.env.CUBE_CLOUD_DEPLOY_AUTH); if (!payload.url) { throw new Error('Malformed token in CUBE_CLOUD_DEPLOY_AUTH'); } if (url && payload.url !== url) { throw new Error('CUBE_CLOUD_DEPLOY_AUTH token doesn\'t match url in .cubecloud'); } return { [payload.url]: { auth: process.env.CUBE_CLOUD_DEPLOY_AUTH } }; } const config = await this.loadConfig(); if (config.auth) { return config.auth; } else { const auth = await inquirer.prompt([{ name: 'auth', message: `Cube Cloud Auth Token${url ? ` for ${url}` : ''}` }]); const authToken = auth.auth; return (await this.addAuthToken(authToken, config)).auth; } }
/** * Check that a JWT has Ask terms accepted. */ function validateAskPermission (token) { const header = jwt.decode(token) return validateToken(token) && header[ASK_CLAIM_KEY] }
async function processUpload (args, opts = { private: false, ask: false }) { try { const authToken = await authenticate(args.server, opts) const { email } = jwt.decode(authToken) console.log(`Signed in as ${email}.`) const server = args.server
const { userId, email, communityId } = jwt.decode(token);
const header = jwt.decode(authToken) if (header.name) { console.log(`Signed in as ${header.name} (${header.email}).`)
const { userId, type, dataId } = jwt.decode(token);
/** * * @param message * @returns {*} */ function jwt_decode (message) { return JWT.decode(message) }
const getHeaderFromToken = token => { const decodedToken = jwt.decode(token, { complete: true }); if (!decodedToken) { throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, `provided token does not decode as JWT`); } return decodedToken.header; }
const getHeaderFromToken = token => { const decodedToken = jwt.decode(token, { complete: true }); if (!decodedToken) { throw new Parse.Error( Parse.Error.OBJECT_NOT_FOUND, `provided token does not decode as JWT` ); } return decodedToken.header; }
function getHeaderFromToken(token) { const decodedToken = jwt.decode(token, {complete: true}); if (!decodedToken) { throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, `provided token does not decode as JWT`); } return decodedToken.header; }