Complete the password grant

@return array

@throws
968380
public function completeFlow()
    {
        // Get the required params
        $clientId = $this->server->getRequest()->request->get('client_id', $this->server->getRequest()->getUser());
        if (is_null($clientId)) {
            throw new Exception\InvalidRequestException('client_id');
        }

        $clientSecret = $this->server->getRequest()->request->get('client_secret',
            $this->server->getRequest()->getPassword());
        if (is_null($clientSecret)) {
            throw new Exception\InvalidRequestException('client_secret');
        }

        // Validate client ID and client secret
        $client = $this->server->getClientStorage()->get(
            $clientId,
            $clientSecret,
            null,
            $this->getIdentifier()
        );

        if (($client instanceof ClientEntity) === false) {
            $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
            throw new Exception\InvalidClientException();
        }
        $request = $this->server->getRequest()->request;
        if(is_null($request->get('facebook_token') && is_null($request->get("device_id")))) {
                $username = $request->get('username', $request->get('email',null));
                if (is_null($username)) {
                    throw new Exception\InvalidRequestException('username');
                }

                $password = $this->server->getRequest()->request->get('password', null);
                if (is_null($password)) {
                    throw new Exception\InvalidRequestException('password');
                }
        }


        // Check if user's username and password are correct
        $userId = call_user_func($this->getVerifyCredentialsCallback(), isset($username) ? $username : null, isset($password) ? $password: null);

        if ($userId === false) {
            $this->server->getEventEmitter()->emit(new Event\UserAuthenticationFailedEvent($this->server->getRequest()));
            throw new Exception\InvalidCredentialsException();
        }

        // Validate any scopes that are in the request
        $scopeParam = $this->server->getRequest()->request->get('scope', '');
        $scopes = $this->validateScopes($scopeParam, $client);

        // Create a new session
        $session = new SessionEntity($this->server);
        $session->setOwner('user', $userId);
        $session->associateClient($client);

        // Generate an access token
        $accessToken = new AccessTokenEntity($this->server);
        $accessToken->setId(SecureKey::generate());
        $accessToken->setExpireTime($this->getAccessTokenTTL() + time());

        // Associate scopes with the session and access token
        foreach ($scopes as $scope) {
            $session->associateScope($scope);
        }

        foreach ($session->getScopes() as $scope) {
            $accessToken->associateScope($scope);
        }

        $this->server->getTokenType()->setSession($session);
        $this->server->getTokenType()->setParam('access_token', $accessToken->getId());
        $this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());

        // Associate a refresh token if set
        if ($this->server->hasGrantType('refresh_token')) {
            $refreshToken = new RefreshTokenEntity($this->server);
            $refreshToken->setId(SecureKey::generate());
            $refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
            $this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId());
        }

        // Save everything
        $session->save();
        $accessToken->setSession($session);
        $accessToken->save();

        if ($this->server->hasGrantType('refresh_token')) {
            $refreshToken->setAccessToken($accessToken);
            $refreshToken->save();
        }

        return $this->server->getTokenType()->generateResponse();
    }
348081
public function getPassword() : ?string 
    {
        if ( ! $this->hasPassword()) {
            $this->setPassword($this->getDefaultPassword());
        }
        return $this->password;
    }
1062765
public function getAuthApis()
    {
        $menu = $this->getMenu();
        
        if (!$menu) {
            return $this->extendPermissionApis();
        }
        
        return ArrayHelper::merge($this->extendPermissionApis(), $menu->getPermissionApis());
    }
1232590
private function getCredentials()
    {
        $options = ['--config ui.interactive' => 'no', '--config auth.x.prefix' => 'http://'];

        $repository = $this->credentials->getCurrentRepository();
        if ($user = $repository->username) {
            $options['--config auth.x.username'] = $user;
        }
        if ($pass = $repository->password) {
            $options['--config auth.x.password'] = $pass;
        }

        return $options;
    }
451306
public function getPassword()
    {
        if (null !== $this->password) {
            return $this->password;
        }

        $this->parseUserInfo();

        return $this->password;
    }
1136894
public function getAccessTokenRules()
    {
        if (!is_string($this->accessTokenAttribute) || empty($this->accessTokenAttribute)) {
            return [];
        }
        if (empty($this->accessTokenRules)) {
            $this->accessTokenRules = [
                [[$this->accessTokenAttribute], 'required'],
                [[$this->accessTokenAttribute], 'string', 'max' => 40],
            ];
        }
        return $this->accessTokenRules;
    }
184194
public function getPasswordHistories()
    {
        if (empty($this->passwordHistoryClass) || !class_exists($this->passwordHistoryClass)) {
            return false;
        }
        $class = $this->passwordHistoryClass;
        return $class::find()->createdBy($this)->orderByCreatedAt(SORT_DESC)->all();
    }
579948
public function getPassword()
    {
        if ($this->isSlave() && ! $this->password) {
            return $this->_master->getPassword();
        }
        return $this->password;
    }
1105853
public function confirmResetPassword()
    {
        $errorMessage = null;

        $login = Common::getRequestVar('login', '');
        $resetToken = Common::getRequestVar('resetToken', '');

        try {
            $this->passwordResetter->confirmNewPassword($login, $resetToken);
        } catch (Exception $ex) {
            Log::debug($ex);

            $errorMessage = $ex->getMessage();
        }

        if (is_null($errorMessage)) { // if success, show login w/ success message
            return $this->resetPasswordSuccess();
        } else {
            // show login page w/ error. this will keep the token in the URL
            return $this->login($errorMessage);
        }
    }
1025970
public function getCredentials()
    {
        if ($this->login) return array( $this->login, $this->password);

        //Try to find the password inside symfony configuration
        if ($this->isSymfony() && $this->symfonyContainer->hasParameter('pb_private_key')) {
            return array('api', $this->symfonyContainer->getParameter('pb_private_key'));
        }

        //Using static PureBilling as fallback
        if (class_exists('\PureBilling') && \PureBilling::getPrivateKey()) {
            return array('api', \PureBilling::getPrivateKey());
        }
    }
968611
public function passwordAction()
    {
        $minLength = $this->container->getParameter('phlexible_user.password.min_length');

        $generator = new PasswordGenerator();
        $password = $generator->create($minLength, PasswordGenerator::TYPE_UNPRONOUNCABLE);

        return new JsonResponse(
            [
                'password' => $password,
                'success' => true,
            ]
        );
    }
822289
public function getPassword()
    {
        if (isset($this->config['mail']['encrypt'])) {
            switch ($this->config['mail']['encrypt']) {
                case 'base64':
                    return base64_decode($this->config['mail']['password']);
            }
        }
        return $this->config['mail']['password'];
    }
1039156
public function digest()
    {
        $headers = $this->headers();
        if (!isset($headers['WWW-Authenticate'])) {
            return [];
        }
        $auth = $this->_classes['auth'];
        return $auth::decode($headers['WWW-Authenticate']);
    }
79235
public function pass()
    {
        $action      = $this->getParameter('action');

        return $this->Permissions->checkPermission($action, $this->getLocal('SiteSlug'));
    }
593243
protected function getAuth()
    {
        if (isset($this->auth['username']) && isset($this->auth['password'])) {
            return [$this->auth['username'], $this->auth['password']];
        }
    }
1119443
function get_passwords()
    {
        if ($config = $_SESSION['enigma_pass']) {
            $config = $this->rc->decrypt($config);
            $config = @unserialize($config);
        }

        $threshold = $this->password_time ? time() - $this->password_time : 0;
        $keys      = array();

        // delete expired passwords
        foreach ((array) $config as $key => $value) {
            if ($threshold && $value[1] < $threshold) {
                unset($config[$key]);
                $modified = true;
            }
            else {
                $keys[$key] = $value[0];
            }
        }

        if ($modified) {
            $_SESSION['enigma_pass'] = $this->rc->encrypt(serialize($config));
        }

        return $keys;
    }
974744
public static function getSavedRoutes()
    {
        $result = [];
        foreach (Yii::$app->getAuthManager()->getPermissions() as $name => $value) {
            if ($name[0] === '/' && substr($name, -1) != '*') {
                $result[] = $name;
            }
        }

        return $result;
    }