Skip to content

feat: added support for API tokens authentication with optional automatic token rotation and storage layer (APPS-16010) - #85

Open
jszymanski-rtbh wants to merge 2 commits into
masterfrom
APPS-16010-api-tokens-authentication-support
Open

feat: added support for API tokens authentication with optional automatic token rotation and storage layer (APPS-16010)#85
jszymanski-rtbh wants to merge 2 commits into
masterfrom
APPS-16010-api-tokens-authentication-support

Conversation

@jszymanski-rtbh

Copy link
Copy Markdown

No description provided.

@jszymanski-rtbh
jszymanski-rtbh requested a review from a team as a code owner July 3, 2026 17:17
Comment thread src/ReportsApi.php
Comment on lines +128 to +141
{
if ($this->_auth instanceof ApiTokenAuth) {
return $this->_createStaticTokenClient($this->_auth);
}

if ($this->_auth instanceof DynamicApiTokenAuth) {
return $this->_createDynamicTokenClient($this->_auth);
}

if ($this->_auth instanceof CookieAuth) {
return $this->_createCookieAuthenticatedClient($this->_auth);
}
throw new ReportsApiException('Unsupported authentication method: ' . get_class($this->_auth));
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match case jest od php 8

@jszymanski-rtbh
jszymanski-rtbh force-pushed the APPS-16010-api-tokens-authentication-support branch from 3db41b6 to 7037bf9 Compare July 3, 2026 17:32
Comment thread bin/api-tokens
fwrite(STDERR, "Cannot locate vendor/autoload.php. Run composer install.\n");
exit(1);
}
require $autoload;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tutaj ścieżka do autoload.php różni się w zależności od instalacji: jako dependency vs jako projekt lokalny

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warto zatem to skomentować w pliku

@jszymanski-rtbh
jszymanski-rtbh requested a review from peku33 July 3, 2026 17:38
Comment thread README.rst
$info = $api->getUserInfo();


Cookie (username / password) Authentication

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basic?

Comment thread README.rst
Authentication methods
----------------------

The SDK supports several authentication methods. ``ReportsApiSession`` accepts a single ``Auth`` object. You can choose from `ApiTokenAuth`, `DynamicApiTokenAuth` or `CookieAuth`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DynamicApiTokenAuth to typ abstrakcyjny, nie można go wybrać. Dopiero jego implementuje np. ApiTokenManager (który nota bene nie jest tu opisany bezpośrednio). To samo jeśli chodzi o CHANGELOG.md

Comment thread CHANGELOG.md
@@ -1,3 +1,41 @@
# v9.0.0
[breaking change] `ReportsApiSession` constructor now takes a single `Auth` object instead of `($username, $password)`. You can choose from `ApiTokenAuth`, `DynamicApiTokenAuth` or `CookieAuth`(old username&password method).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pamiętaj o temacie podbicia paczek i samego php, i oczywiście zamieszczenia tu informacji

$storage = new JsonFileApiTokenStorage($this->path);
$apiToken = $this->apiToken;
$storage->acquireForSave(function () use ($storage, $apiToken) {
$storage->save($apiToken);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W jaki sposób tu system plików jest mockowany? Czy to nam jednak pisze po oryginalnym systemie?

return new InMemoryApiTokenStorage(new ApiToken(self::TOKEN, new \DateTimeImmutable($expiresAt)));
}

// configre() tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

public function acquireForSave(callable $callback)
{
$factory = new LockFactory(new FlockStore(dirname($this->path)));
$lock = $factory->createLock(basename($this->path), 60);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wygasa?


// Drop any cached token so reads inside the lock come from disk (e.g. the
// manager's re-check after another process may have rotated the token).
$this->cache = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

na pewno? a jak to zrobiliśmy w pythonie?

// Get ApiToken from cache if set
if ($this->cache !== null) {
[$apiToken, $cachedAt] = $this->cache;
if ((microtime(true) - $cachedAt) < self::CACHE_TTL_SECONDS) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

czasami używamy datetime, a czasami plain timestampów?

throw new ApiTokenStorageException("Cannot write API token file {$this->path}: " . $exception->getMessage());
}

$this->cache = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Comment thread composer.json
Comment on lines +13 to +15
"symfony/console": "^5.4",
"symfony/filesystem": "^5.4",
"symfony/lock": "^5.4"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warto sprawdzić na ile zależności się to przełożyło

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants