/** * Create a new token (and generate the token) * * @param string $redirectUri * @param TokenOwnerInterface $owner * @param Client $client * @param string|string[]|Scope[] $scopes * @return AuthorizationCode * @throws OAuth2Exception */ public function createToken($redirectUri, $owner, $client, $scopes) : AuthorizationCode { if (empty($scopes)) { $scopes = $this->scopeService->getDefaultScopes(); } else { $this->validateTokenScopes($scopes); } do { $token = AuthorizationCode::createNewAuthorizationCode($this->serverOptions->getAuthorizationCodeTtl(), $redirectUri, $owner, $client, $scopes); } while ($this->tokenRepository->tokenExists($token->getToken())); return $this->tokenRepository->save($token); }
/** * @todo I don't get this check */ public function testDoNotSupportLongLiveToken() { $authorizationCode = AuthorizationCode::createNewAuthorizationCode(0, 'http://www.example.com', null, null, 'read write'); $this->assertTrue($authorizationCode->isExpired()); }
/** * @return AuthorizationCode */ private function getValidAuthorizationCode($redirectUri = null, $owner = null, $client = null, $scopes = null) { $validDate = (new \DateTimeImmutable())->add(new DateInterval('PT1H')); $token = AuthorizationCode::reconstitute(['token' => 'azerty_auth', 'owner' => $owner, 'client' => $client, 'scopes' => $scopes ?? ['read'], 'expiresAt' => $validDate, 'redirectUri' => $redirectUri ?? '']); return $token; }