Creates a new token.

`cb` is passed with the newly created token or:

* exceptions.BadRequest: if `body` does not satisfy the schema
* exceptions.AlreadyExists: if a token with the same `token` already exists

@param {Object} body
@param {Function} cb
764645
function create(body, cb) {
  var validates = Schema(body);

  if(!validates) {
    return cb(new exceptions.BadRequest());
  }

  body.expires_at = stampify(conf.session_maxage);

  var q = qb.insert(body);
  db.getClient(function(err, client, done) {
    client.query(q[0], q[1], function(err, r) {
      if(err) {
        if(err.code == 23505) {
          err = new exceptions.AlreadyExists();
        }
        cb(err);
        done(err);
      } else {
        cb(null, r.rows[0]);
        done();
      }
    });
  });
}
1275860
function createSession(config, cb) {
  checkOpts(config, cb)

  cb = utils.callOnce(cb)

  var url = config.url
  var key = config.key

  config = {
    url: url,
    key: key
  }

  session.createSession(config, cb)
}
677058
function (context, token, callback) {
            var authentication = this.$.dataSource.createEntity(Authentication, token),
                self = this;

            // setup authentication
            this.$stage.$bus.setUp(authentication);

            flow()
                .seq("authentication", function (cb) {
                    authentication.fetch({noCache: true}, function (err) {
                        if (!err) {
                            var now = new Date();
                            if (authentication.$.updated.getTime() < now.getTime() - (1000 * self.$.tokenLifeTime)) {
                                // remove token
                                authentication.remove();
                                // return error
                                err = AuthenticationError.AUTHENTICATION_EXPIRED;
                            }
                        } else {
                            // TODO: change to authentication not found
                            err = AuthenticationError.AUTHENTICATION_EXPIRED;
                        }

                        cb(err, authentication);
                    });
                })
                .seq(function (cb) {
                    this.vars.authentication.set('updated', new Date());
                    this.vars.authentication.save(null, cb);
                })
                .seq(function (cb) {
                    // init authentication
                    this.vars.authentication.init(cb);
                })
                .exec(function (err, results) {
                    authentication = results.authentication;
                    if (!err && authentication) {
                        context.user.addAuthentication(authentication);
                    }
                    callback && callback(err, authentication);
                });
        }
289152
function (url, method, cb) {

            request({
                url: url,
                method: method
            }, function (error, response, body) {

                if (error) {
                    return cb(error);
                }

                if (response.statusCode == 200 || response.statusCode == 201) {

                    return cb(null, body);

                } else {

                    return cb(new Error('Server responded with error: ' + response.statusCode));

                }

            })

        }
68610
def make_token_post(server, data):
    
    try:
        response = requests.post(server + TOKEN_ENDPOINT, data=data, timeout=TIMEOUT)
        body = response.json()
    except Exception as e:
        log.warning('Other error when exchanging code', exc_info=True)
        raise OAuthException(
            error='Authentication Failed',
            error_description=str(e))
    if 'error' in body:
        log.error(body)
        raise OAuthException(
            error=body.get('error', 'Unknown Error'),
            error_description = body.get('error_description', ''))
    return body
868613
function create(object, callback) {
    self.emit('create', object)
    callback = callback || emptyFn
    // clone the object
    var extendedObject = extend({}, object)

    if (!extendedObject[options.idProperty]) {
      idSeq += 1
      extendedObject[options.idProperty] = '' + idSeq
    } else {
      if (findById(extendedObject[options.idProperty]) !== null) {
        return callback(new Error('Key ' + extendedObject[options.idProperty] + ' already exists'))
      }
      // if an id is provided, cast to string.
      extendedObject[options.idProperty] = '' + extendedObject[options.idProperty]
    }
    data.push(extend({}, extendedObject))
    self.emit('afterCreate', extendedObject)
    callback(undefined, extendedObject)
  }
119303
function createAction(config){
    // make a copy of config with defaults
    config = basis.object.extend({
      prepare: nothingToDo,
      request: nothingToDo
    }, config);

    // if body is function take in account special action context
    if (typeof config.body == 'function')
    {
      var bodyFn = config.body;
      config.body = function(){
        return bodyFn.apply(this.context, this.args);
      };
    }

    // splice properties
    var fn = basis.object.splice(config, ['prepare', 'request']);
    var callback = basis.object.merge(
      DEFAULT_CALLBACK,
      basis.object.splice(config, ['start', 'success', 'failure', 'abort', 'complete'])
    );

    // lazy transport
    var getTransport = basis.fn.lazyInit(function(){
      var transport = resolveTransport(config);

      transport.addHandler(CALLBACK_HANDLER, callback);

      return transport;
    });

    return function action(){
      // this - instance of AbstractData
      if (this.state != STATE_PROCESSING)
      {
        if (fn.prepare.apply(this, arguments))
        {
          /** @cut */ basis.dev.info('Prepare handler returns trulthy result. Operation aborted. Context: ', this);
          return Promise.reject('Prepare handler returns trulthy result. Operation aborted. Context: ', this);
        }

        var request;
        var requestData = basis.object.complete({
          origin: this,
          bodyContext: {
            context: this,
            args: basis.array(arguments)
          }
        }, fn.request.apply(this, arguments));

        // if body is function take in account special action context
        if (typeof requestData.body == 'function')
        {
          var bodyFn = requestData.body;
          requestData.body = function(){
            return bodyFn.apply(this.context, this.args);
          };
        }

        // do a request
        if (request = getTransport().request(requestData))
          return new Promise(function(fulfill, reject){
            request.addHandler(PROMISE_REQUEST_HANDLER, {
              request: request,
              fulfill: fulfill,
              reject: reject
            });
          });

        return Promise.reject('Request is not performed');
      }
      else
      {
        /** @cut */ basis.dev.warn('Context in processing state. Operation aborted. Context: ', this);
        return Promise.reject('Context in processing state, request is not performed');
      }
    };
  }
105213
function parseResponse(cb) {
  return function parse(err, response, body) {
    // TODO Handel the errors
    cb(err, JSON.parse(body))
  }
}
652586
function touch(token, cb) {
  var date = stampify(conf.session_maxage);
  db.getClient(function(err, client, done) {
    client.query("UPDATE tokens SET expires_at = $1 WHERE token = $2", [date, token], function() {
      cb.apply(null, arguments);
      done();
    });
  });
}
1062342
function(cb) {
        var at = this.brain.get(this.TOKEN_KEY),
            rt = this.brain.get(this.REFRESH_KEY);

        if (at == null || rt == null) {

            cb({
                err: null,
                msg: 'Error: No tokens found. Please authorize this app and store a refresh token'
            });
            return;
        }

        var expirTime = this.brain.get(this.EXPIRY_KEY),
            curTime = (new Date()) / 1;

        var self = this;
        if (expirTime < curTime) {
            this.oauthClient.refreshAccessToken(function(err, token) {
                if (err != null) {
                    cb({
                        err: err,
                        msg: 'Google Authentication Error: error refreshing token'
                    }, null);
                    return;
                }

                self.storeToken(token);
                cb(null, {
                    resp: token,
                    msg: 'Token refreshed'
                });
            });
        } else {
            cb(null);
        }
    }
544319
def create(self, **kwargs):
        """"""
        body = self.client.create(url=self.base_url,
                                  json=kwargs)
        return body
1196729
function(handler, cbvalidate) {
        var req   = handler.httpRequest;
        var A2    = req.method + ":" + this.digestParts["uri"];
        var self  = this;

        if (this.digestParts["qop"] == "auth-int") {
            // Making sure we support this qop value
            if (!(this.qop & QOP_AUTHINT))
                return cbvalidate(false);
            // We need to add an md5 of the entire request body to the A2 part of the hash
            handler.getRequestBody("utf8", null, false, function(noop, body) {
                A2 += ":" + Util.createHash(body);
                afterBody();
            });
        }
        else {
            // We need to make sure we support this qop value
            if (!(this.qop & QOP_AUTH))
                return cbvalidate(false);
            afterBody();
        }

        function afterBody() {
            A2 = Util.createHash(A2);

            var validResponse = Util.createHash(self.A1 + ":" + self.digestParts["nonce"] + ":"
                + self.digestParts["nc"] + ":" + self.digestParts["cnonce"] + ":"
                + self.digestParts["qop"] + ":" + A2);

            cbvalidate(self.digestParts["response"] == validResponse);
        }
    }
405857
function(token, cb){
      // deserialize the token iss
      var _iss = token.iss.split('|');

      waterlock.User.findOne(_iss[0]).exec(function(err, user){
        if(err){
          waterlock.logger.debug(err);
        }

        cb(err, user);
      });
    }
676161
function startTagInTableBody(p, token) {
    const tn = token.tagName;

    if (tn === $.TR) {
        p.openElements.clearBackToTableBodyContext();
        p._insertElement(token, NS.HTML);
        p.insertionMode = IN_ROW_MODE;
    } else if (tn === $.TH || tn === $.TD) {
        p.openElements.clearBackToTableBodyContext();
        p._insertFakeElement($.TR);
        p.insertionMode = IN_ROW_MODE;
        p._processToken(token);
    } else if (
        tn === $.CAPTION ||
        tn === $.COL ||
        tn === $.COLGROUP ||
        tn === $.TBODY ||
        tn === $.TFOOT ||
        tn === $.THEAD
    ) {
        if (p.openElements.hasTableBodyContextInTableScope()) {
            p.openElements.clearBackToTableBodyContext();
            p.openElements.pop();
            p.insertionMode = IN_TABLE_MODE;
            p._processToken(token);
        }
    } else {
        startTagInTable(p, token);
    }
}
157613
function create(name, config, cb) {
  var opts = {
    body: config,
    contentType: 'application/xml',
  };
  this.remoteAccessApi.postCreateItem(name, _.merge(opts, this.opts.headers), cb);
}
568120
def invalidate_token(self, body, params=None):
        
        if body in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'body'.")
        return self.transport.perform_request(
            "DELETE", "/_security/oauth2/token", params=params, body=body
        )
1336933
function createToken(options) {
    const newToken = chevrotain.createToken(options)
    allTokens.push(newToken)
    return newToken
}