Add new app and token
969858
private function addApp ()
		{
			$appNew = new Apiapp();
			if (Yii::$app->request->post('method') == 'apiapp')
			{
				$post = Yii::$app->request->post();

				if ($post[ 'id' ])
					$appNew = Apiapp::findOne($post[ 'id' ]);

				$appNew->setAttributes([ 'name' => $post[ 'name' ] ]);
				$appNew->token = StringHelper::random(16);
				if ($appNew->validate())
				{
					$appNew->save();
					if (!$post[ 'id' ])
						Yii::$app->session->set('viewID', $appNew->id);
					$url = Yii::$app->request->referrer . '#' . $appNew->name;
					$appNew->setAttributes([ 'name' => '', 'token' => '' ]);
					LogManager::info(Yii::tr('User {user} has created API application {name}.', [ 'user' => Html::a(Yii::$app->user->identity->name, Url::toRoute([ 'user/view', 'id' => Yii::$app->user->id ])), 'name' => $post[ 'name' ] ]));

					Yii::$app->response->redirect($url);
					Yii::$app->end();
				}
			}

			return $appNew;
		}
1069123
public function add()
	{
		// Get the hook we're setting
		$trigger = $this->arguments->getOpt(3);
		$hook    = $this->arguments->getOpt(4);

		// Delete the primary args so they aren't added as top level config values
		$this->arguments->deleteOpt(3);
		$this->arguments->deleteOpt(4);

		// Set the new hooks argument
		$this->arguments->setOpt('hooks', array($trigger => array($hook)));

		// Redirect back to the basic configuration set method
		App::get('client')->call('configuration', 'set', $this->arguments, $this->output);
	}
420786
def add(self, name, func):
        '''  '''
        if name not in self.hooks:
            raise ValueError("Unknown hook name %s" % name)
        was_empty = self._empty()
        self.hooks[name].append(func)
        if self.app and was_empty and not self._empty(): self.app.reset()
122610
def add_or_update(user_id, app_id):
        '''
        
        '''

        rec = MCollect.get_by_signature(user_id, app_id)

        if rec:
            entry = TabCollect.update(
                timestamp=int(time.time())
            ).where(TabCollect.uid == rec.uid)
            entry.execute()
        else:
            TabCollect.create(
                uid=tools.get_uuid(),
                user_id=user_id,
                post_id=app_id,
                timestamp=int(time.time()),
            )
743945
def oauth_token_create(self, data, **kwargs):
        ""
        api_path = "/api/v2/oauth/tokens.json"
        return self.call(api_path, method="POST", data=data, **kwargs)
442238
function setupResourceServer(app, options, models) {

    function checkAccessToken(req, accessToken, done) {
        debug('Verifying access token %s', accessToken);
        models.AccessTokens.find(accessToken, function (err, token) {
            if (err || !token) {
                return done(err);
            }

            debug('Access token found: %j', token);

            if (isExpired(token)) {
                return done(new TokenError('Access token is expired',
                    'invalid_grant'));
            }

            var userId = token.userId || token.resourceOwner;
            var appId = token.appId || token.clientId;

            var user, app;
            async.parallel([
                function lookupUser(done) {
                    if (userId == null) {
                        return process.nextTick(done);
                    }
                    models.Users.find(userId, function (err, u) {
                        if (err) {
                            return done(err);
                        }
                        if (!u) {
                            return done(
                                new TokenError('Access token has invalid user id: ' +
                                    userId, 'invalid_grant'));
                        }
                        debug('User found: %s', userInfo(u));
                        user = u;
                        done();
                    });
                },
                function lookupApp(done) {
                    if (appId == null) {
                        return process.nextTick(done);
                    }
                    models.Clients.find(appId, function (err, a) {
                        if (err) {
                            return done(err);
                        }
                        if (!a) {
                            return done(
                                new TokenError('Access token has invalid app id: ' + appId,
                                    'invalid_grant'));
                        }
                        debug('Client found: %s', clientInfo(a));
                        app = a;
                        done();
                    });
                }], function (err) {
                if (err) {
                    return done(err);
                }
                if (options.addHttpHeaders) {
                    var prefix = 'X-OAUTH2-';
                    if (typeof options.addHttpHeaders === 'string') {
                        prefix = options.addHttpHeaders;
                    }
                    if (appId != null) {
                        req.headers[prefix + 'CLIENT-ID'] = appId;
                    }
                    if (userId != null) {
                        req.headers[prefix + 'USER-ID'] = userId;
                    }
                }
                var authInfo =
                {accessToken: token, user: user, app: app, client: app};
                done(null, user || {}, authInfo);
            });
        });
    }

    var verifyAccessToken = checkAccessToken;
    if (typeof options.checkAccessToken === 'function') {
        verifyAccessToken = options.checkAccessToken;
    }

    function accessTokenValidator(req, accessToken, done) {
        verifyAccessToken(req, accessToken, function (err, user, info) {
            if (!err && info) {
                req.accessToken = info.accessToken;
            }
            done(err, user, info);
        });
    }

    /**
     * BearerStrategy
     *
     * This strategy is used to authenticate users based on an access token (aka a
     * bearer token).  The user must have previously authorized a client
     * application, which is issued an access token to make requests on behalf of
     * the authorizing user.
     */
    passport.use('copress-oauth2-bearer',
        new BearerStrategy({passReqToCallback: true}, accessTokenValidator)
    );

    passport.use('copress-oauth2-mac',
        new MacStrategy({passReqToCallback: true, jwtAlgorithm: 'HS256'},
            function (req, accessToken, done) {
                accessTokenValidator(req, accessToken, function (err, user, info) {
                    if (err || !user) {
                        return done(err, user, info);
                    }
                    var client = info && info.client;
                    var secret = client.clientSecret || client.restApiKey;
                    try {
                        var token = jwt.verify(accessToken, 'HS256', secret);
                        debug('JWT token verified: %j', token);
                    } catch (err) {
                        debug('Fail to verify JWT: %j', err);
                        done(err);
                    }
                    done(null, user, info);
                });
            })
    );

    /**
     * Return the middleware chain to enforce oAuth 2.0 authentication and
     * authorization
     * @param {Object} [options] Options object
     * - scope
     * - jwt
     */
    function authenticate(options) {
        options = options || {};

        var authenticators = [
            passport.authenticate(['copress-oauth2-bearer', 'copress-oauth2-mac'],
                options)];
        if (options.scopes || options.scope) {
            authenticators.push(scopeValidator(options));
        }
        authenticators.push(oauth2Provider.errorHandler());
        return authenticators;
    }

    return authenticate;
}
75126
def add_application(self, application_id, **kwargs):
        
        path = 'group/%s/application' % self.id

        data = {'application_id': application_id}
        if kwargs:
            data["options"] = kwargs

        self.api.request(path, data)
962259
def app_start(name, profile, **kwargs):
    
    ctx = Context(**kwargs)
    ctx.execute_action('app:start', **{
        'node': ctx.repo.create_secure_service('node'),
        'name': name,
        'profile': profile
    })
59073
def add_user(username,
             deployment_name,
             token_manager=None,
             app_url=defaults.APP_URL):
    
    deployment_id = get_deployment_id(deployment_name,
                                      token_manager=token_manager,
                                      app_url=app_url)

    account_id = accounts.get_account_id(username,
                                         token_manager=token_manager,
                                         app_url=app_url)

    headers = token_manager.get_access_token_headers()
    deployment_url = environment.get_deployment_url(app_url=app_url)
    response = requests.put('%s/api/v1/deployments/%s/accounts/%s' %
                            (deployment_url, deployment_id, account_id),
                            headers=headers)

    if response.status_code == 204:
        return response.text
    else:
        raise JutException('Error %s: %s' % (response.status_code, response.text))
688962
def _addappt(self, iden, appt):
        '''
        
        '''
        if appt.nexttime:
            heapq.heappush(self.apptheap, appt)
        self.appts[iden] = appt
        if self.apptheap and self.apptheap[0] is appt:
            self._wake_event.set()
204699
def add_token(self, token, token_handler, request):
        
        # Only add a hybrid access token on auth step if asked for
        if not request.response_type in ["token", "code token", "id_token token", "code id_token token"]:
            return token

        token.update(token_handler.create_token(request, refresh_token=False))
        return token
23815
function (token, deviceId, appId, versionId, policy, events) {
    var options = {
      deviceId: deviceId,
      appId: appId,
      versionId: versionId,
      policy: policy
    };

    require('./helpers').startAppInstall(options, events);

  }
1241109
def adduser(app, username, password):
    """"""
    with app.app_context():
        create_user(username=username, password=password)
        click.echo('user created!')
1350443
function add(data, callback) {
        var id = hat() + '.json';
        repo.contents(id).add({
            content: btoa(JSON.stringify(data)),
            branch: options.branch,
            message: '+'
        }, function(err, res) {
           callback(err, res, id);
        });
    }
1286320
public function addToken(Token $token)
    {
        $this->tokens[$this->getAppKey()][$token->getTokenUUID()->composeUUID()] = $token;
    }
89036
def add_token(self, token_identifier, delegation_token):
    
    self.send_add_token(token_identifier, delegation_token)
    return self.recv_add_token()
1145753
def app_create(self, data, **kwargs):
        ""
        api_path = "/api/v2/apps.json"
        return self.call(api_path, method="POST", data=data, **kwargs)