Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
try {
// try to load a locally stored token and use that
log.debug('Using token file ' + tokenPath)
let stored = require(tokenPath)
let cozyClient = new cozy.Client()
cozyClient.init({
cozyURL: url,
token: stored.token
})
resolve(cozyClient)
} catch (err) {
reject(err)
}
})
}
exported.getClientWithoutToken = tokenPath => (url, docTypes = []) => {
let permissions = docTypes.map(docType => docType.toString() + ':ALL')
// Needed for ACH revocation after execution
permissions.push('io.cozy.oauth.clients:ALL')
let cozyClient = new cozy.Client({
cozyURL: url,
oauth: {
storage: new cozy.MemoryStorage(),
clientParams: {
redirectURI: 'http://localhost:3333/do_access',
softwareID: SOFTWARE_ID,
clientName: CLIENT_NAME,
scopes: permissions
},
onRegistered: onRegistered
}
})
return cozyClient.authorize().then(creds => {
let token = creds.token.accessToken
cozyClient._token = new AppToken({ token })
exported.getClientWithTokenString = tokenString => async url => {
const client = new cozy.Client()
client.init({ cozyURL: url, token: tokenString })
return client
}