Add grant type

@param GrantTypeInterface $grantType  - the grant type to add for the specified identifier
@param string|null        $identifier - a string passed in as "grant_type" in the response that will call this grantType
16003
public function addGrantType(GrantTypeInterface $grantType, $identifier = null)
    {
        if (is_null($identifier) || is_numeric($identifier)) {
            $identifier = $grantType->getQueryStringIdentifier();
        }

        $this->grantTypes[$identifier] = $grantType;
    }
951432
public function authenticate($grantType = 'client_credentials')
    {
        if ($grantType == 'client_credentials') {
            $cc = new oAuthClientCredentials;
            $this->authorization = $cc->clientCredentials();
        } elseif ($grantType = 'authorization_code') {
            // Authentication has already taken place so we just need an instance of authCode
            // that has the necessary credentials
            $this->authorization = new oAuthAuthorizationCode();
        } else {
            // Unknown grant type
            return false;
        }

        return $this;
    }
327576
public function enableGrantType(GrantTypeInterface $grantType, DateInterval $accessTokenTTL = null)
    {
        if ($accessTokenTTL instanceof DateInterval === false) {
            $accessTokenTTL = new DateInterval('PT1H');
        }

        $grantType->setAccessTokenRepository($this->accessTokenRepository);
        $grantType->setClientRepository($this->clientRepository);
        $grantType->setScopeRepository($this->scopeRepository);
        $grantType->setDefaultScope($this->defaultScope);
        $grantType->setPrivateKey($this->privateKey);
        $grantType->setEmitter($this->getEmitter());
        $grantType->setEncryptionKey($this->encryptionKey);

        $this->enabledGrantTypes[$grantType->getIdentifier()] = $grantType;
        $this->grantTypeAccessTokenTTL[$grantType->getIdentifier()] = $accessTokenTTL;
    }
769146
public function addIdentifier($identifier)
    {
        $this->validateIdentifier($identifier);

        if (in_array($identifier, $this->identifiers)) {
            throw new InvalidIdentifierException('Error: Cannot add the identifier "'.$identifier.'" twice');
        }

        $this->identifiers[] = $identifier;
    }
517525
def add_grant(self, grant):
        
        if hasattr(grant, "expires_in"):
            self.token_generator.expires_in[grant.grant_type] = grant.expires_in

        if hasattr(grant, "refresh_expires_in"):
            self.token_generator.refresh_expires_in = grant.refresh_expires_in

        self.grant_types.append(grant)
385488
public function add_resource(cc_i_resource $res, $identifier = null, $type = 'webcontent') {

        if (!$this->ccobj->valid($type)) {
            throw new Exception("Type invalid...");
        }

        if ($res == null) {
            throw new Exception('Invalid Resource or dont give it');
        }
        $rst = $res;

        // TODO: This has to be reviewed since it does not handle multiple files properly.
        // Dependencies.
        if (is_object($identifier)) {
            $this->activemanifest->create_resource_node($rst, $this->doc, $identifier);
        } else {
            $nresnode   = null;

            $rst->type = $type;
            if (!cc_helpers::is_html($rst->filename)) {
                $rst->href = null;
            }

            $this->activemanifest->create_resource_node($rst, $this->doc, $nresnode);
            foreach ($rst->files as $file) {
                $ident = $this->get_identifier_by_filename($file);
                if ($ident == null) {
                    $newres = new cc_resource($rst->manifestroot, $file);
                    if (!cc_helpers::is_html($file)) {
                         $newres->href = null;
                    }
                    $newres->type = 'webcontent';
                    $this->activemanifest->create_resource_node($newres, $this->doc, $nresnode);
                }
            }
        }

        $tmparray = array($rst->identifier, $rst->files[0]);
        return $tmparray;
    }
610064
public function setRequestType(\AgentSIB\Diadoc\Api\Proto\Events\ResolutionRequestType $value = null)
    {
        $this->RequestType = $value;
    }
258393
protected function configureGrantTypes(AuthorizationServer $authorizationServer, array $config)
    {
        // TODO: Support configuring of the remaining grant types
        foreach ($config as $name => $params) {
            if (!isset($params['class']) || !class_exists($params['class'])) {
                continue;
            }

            /** @var AbstractGrant $grantType */
            $grantType = new $params['class'];

            if (isset($params['access_token_ttl'])) {
                $grantType->setAccessTokenTTL($params['access_token_ttl']);
            }

            if ($grantType instanceof PasswordGrant) {
                /** @var PasswordGrant $grantType */
                if (isset($params['callback'])) {
                    $grantType->setVerifyCredentialsCallback($params['callback']);
                }
            }

            if ($grantType instanceof RefreshTokenGrant) {
                /** @var RefreshTokenGrant $grantType */
                if (isset($params['refresh_token_rotate'])) {
                    $grantType->setRefreshTokenRotation($params['refresh_token_rotate']);
                }
                if (isset($params['refresh_token_ttl'])) {
                    $grantType->setRefreshTokenTTL($params['refresh_token_ttl']);
                }
            }

            $authorizationServer->addGrantType($grantType);
        }
    }
1038650
public function createClient($identifier, array $redirect_uris = array(), array $grant_types = array(), array $scopes = array())
    {
        $client = new \OAuth2\ServerBundle\Entity\Client();
        $client->setClientId($identifier);
        $client->setClientSecret($this->generateSecret());
        $client->setRedirectUri($redirect_uris);
        $client->setGrantTypes($grant_types);

        // Verify scopes
        foreach ($scopes as $scope) {
            // Get Scope
            $scopeObject = $this->sm->findScopeByScope($scope);
            if (!$scopeObject) {
                throw new ScopeNotFoundException();
            }
        }

        $client->setScopes($scopes);

        // Store Client
        $this->em->persist($client);
        $this->em->flush();

        return $client;
    }
1204014
public function getPermissions($type, $identifier)
    {
        $accessControls = $this->accessControlRepository->findByTypeAndId($type, $identifier);

        $permissions = [];
        foreach ($accessControls as $accessControl) {
            $permissions[$accessControl->getRole()->getId()] = $this->maskConverter->convertPermissionsToArray(
                $accessControl->getPermissions()
            );
        }

        return $permissions;
    }
40385
private static function injectGrants(AclAuthorization $acl, $grantType, array $rules)
    {
        foreach ($rules as $set) {
            if (! is_array($set) || ! isset($set['resource'])) {
                continue;
            }

            self::injectGrant($acl, $grantType, $set);
        }

        return $acl;
    }
908302
public function setPermissions($type, $identifier, $permissions)
    {
        foreach ($permissions as $roleId => $rolePermissions) {
            $accessControl = $this->accessControlRepository->findByTypeAndIdAndRole($type, $identifier, $roleId);

            if ($accessControl) {
                $accessControl->setPermissions($this->maskConverter->convertPermissionsToNumber($rolePermissions));
            } else {
                $role = $this->roleRepository->findRoleById($roleId);

                $accessControl = new AccessControl();
                $accessControl->setPermissions($this->maskConverter->convertPermissionsToNumber($rolePermissions));
                $accessControl->setRole($role);
                $accessControl->setEntityId($identifier);
                $accessControl->setEntityClass($type);
                $this->objectManager->persist($accessControl);
            }
        }

        $this->objectManager->flush();
    }
1170821
public function setAllowedGrantTypes($allowedGrantTypes)
    {
        foreach ($allowedGrantTypes as $allowedGrantType) {
            if (!in_array($allowedGrantType, $this->availableGrantTypes)) {
                throw new \Exception('Unknown grant type ' . $allowedGrantType);
            }
        }
        $this->allowedGrantTypes = $allowedGrantTypes;
    }
829811
public function addHandler(string $type, RequestHandlerInterface $handler): void
    {
        $this->handlers[$type] = $handler;
    }
279233
public function onAddedToType(TypeInterface &$type)
    {
        parent::onAddedToType($type);

        $type->addTrait(AdditionalPropertiesInterface::class, AdditionalPropertiesInterfaceImplementation::class)->protectFields($this->getName());
    }
853866
public function add(ResourceInterface $resource): void
    {
        if (!$resource instanceof $this->interface) {
            throw new UnexpectedTypeException($resource, $this->interface);
        }

        if (in_array($resource, $this->findAll())) {
            throw new ExistingResourceException();
        }

        $this->arrayObject->append($resource);
    }
1055065
def add_grant(self, grant):
        """"""
        if not isinstance(grant, AccessTokenGrant):
            raise ValueError('Grant must be an instance of AccessTokenGrant.')
        self.grants.append(grant)