Repository navigation
Conversation
- Availability check uses the token validation request when a token is set, a 200 or 401 response means the server is available. - Tokens which are not 64 characters long are sent only as 'X-Api-Key', server accepts only 64 characters long tokens as Bearer. - Validation requests use a session which becomes the authorized session, so the connection is reused. - 'create_session' does not validate an already validated token again.
This was referenced Oct 30, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog Description
Creating a connection with a token (
ServerAPI,GlobalServerAPI,create_connection) makes 1 request on 1 connection. Before, it made 3 requests on 3 connections, or 4 on 4 with an API key.Part of ynput/ayon-launcher#129.
Additional info
Before, a connection with a token requested, each with
requests.getand therefore each on a new TCP/TLS connection:GET /(web frontend page) to check availabilityGET /api/infoGET /api/users/mewithAuthorization: BearerGET /api/users/mewithX-Api-KeyNow:
GET /api/users/me. A 200 or 401 response means the server is available. Any other response falls back toGET /api/info, which replacesGET /as the availability check.X-Api-Key. The server accepts only 64-character tokens as Bearer (parse_access_tokenin ayon-backend, since 0.5), so the Bearer attempt for a 32-character API key could never succeed. 64-character tokens still try Bearer first, thenX-Api-Key. TryingX-Api-Keyfirst, or sending both headers, isn't an option: the server checksX-Api-Keyfirst, and an invalid API key costs a 0.2 s server-side delay plus a brute-force counter hit.create_sessiondoesn't validate an already validated token again.validate_tokenno longer requests/api/infofirst. It does so only whenusers/mereturns an unexpected status, so a URL that isn't an AYON server still raises.get_user_info_by_tokenhas an optionalsessionargument.Behavior changes:
create_session()no longer re-validates a token that was already validated. A token that became invalid since is still caught: the first request gets 401 and marks it invalid, as before./api/infoinstead of the web frontend page.ServerNotReached. Before, the error depended on whether that server answered/with 200.Measured in AYON launcher startup, together with ynput/ayon-launcher#346, against a local server with 50 ms latency added per request and per new connection:
Not changed here:
get_user_by_tokenreturnsuser_info.data, butUserInfohas nodatafield, so it raisesAttributeErrorwhenever the token is valid.Testing notes:
pytest tests/test_token_validation.py(no server needed).ServerNotReached).