How to use cozy-client-js - 5 common examples

To help you get started, we’ve selected a few cozy-client-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cozy / cozy.github.io / en / ach / libs / getClient.js View on Github external
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)
    }
  })
}
github cozy / cozy.github.io / en / ach / libs / getClient.js View on Github external
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 })
github cozy / cozy.github.io / en / ach / libs / getClient.js View on Github external
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 })

    log.debug('Writing token file to ' + tokenPath)
    fs.writeFileSync(tokenPath, JSON.stringify({ token: token }), 'utf8')
github cozy / cozy.github.io / en / ach / libs / getClient.js View on Github external
exported.getClientWithTokenString = tokenString => async url => {
  const client = new cozy.Client()
  client.init({ cozyURL: url, token: tokenString })
  return client
}
github cozy / cozy.github.io / en / ach / libs / getClient.js View on Github external
const cozy = require('cozy-client-js')
const appPackage = require('../package.json')
const fs = require('fs')
const { addUtilityMethods } = require('./cozy-client-mixin')
const path = require('path')
const AppToken = cozy.auth.AppToken
const log = require('./log')
const { ChainedError } = require('./errors')
const jwt = require('jsonwebtoken')
const CLIENT_NAME = appPackage.name.toUpperCase()
const SOFTWARE_ID = CLIENT_NAME + '-' + appPackage.version

const enableDestroy = require('server-destroy')

const exported = {}

const revokeACHClients = (cozyClient, options) => {
  const { exclude } = options
  return cozyClient.settings.getClients().then(oAuthClients => {
    const revocations = oAuthClients
      .filter(
        oAuthClient =>

cozy-client-js

Javascript library to interact with a cozy

MIT
Latest version published 9 months ago

Package Health Score

53 / 100
Full package analysis