Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the SDK’s access token handling by introducing helpers for decoding access token claims, supporting organization-aware token fetching, and adding supporting tests and utilities.
Changes:
- Add
LogtoUtilities.decodeAccessTokenandJsonValueconvenience accessors to work with structured access token claims. - Extend
LogtoClientaccess token APIs to support organization-specific tokens and new helpers to fetch access token/organization token claims, including tests and mock responses. - Refactor
LogtoCore.fetchToken(refresh-token flow) to centralize payload construction viabuildFetchTokenPayload, and add tests to validate the new behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/LogtoTests/LogtoUtilitiesTests.swift | Adds tests for decoding access tokens (including nested claims) and error handling for malformed tokens. |
| Tests/LogtoTests/LogtoCoreTests+Fetch.swift | Updates refresh-token fetch tests to include the new organizationId parameter. |
| Tests/LogtoMock/NetworkSessionMock.swift | Extends the mock session with a reusable JWT access token and new OIDC/token endpoints for JWT-based flows. |
| Tests/LogtoClientTests/LogtoClient/LogtoClientTests+Fetch.swift | Adjusts access token cache key usage and adds tests for LogtoCore.buildFetchTokenPayload with resource/organization combinations. |
| Tests/LogtoClientTests/LogtoClient/LogtoClientTests+AccessToken.swift | Updates cache key construction to include organization ID and adds tests for organization token fetching and access token claims. |
| Sources/LogtoClient/LogtoClient/LogtoClient+SignIn.swift | Ensures the initial access token after sign-in uses the new (resource, organizationId)-based cache key. |
| Sources/LogtoClient/LogtoClient/LogtoClient+AccessToken.swift | Introduces organization-aware access token keying, extends getAccessToken to accept organizationId, and adds claim-access helpers for resources and organizations. |
| Sources/Logto/Utilities/LogtoUtilities+AccessToken.swift | Adds a utility to decode access token JWT payloads into JsonObject without validation. |
| Sources/Logto/Types/Json.swift | Adds convenience accessors (stringValue, numberValue, etc.) and isNull to JsonValue for easier claim inspection. |
| Sources/Logto/Core/LogtoCore+Fetch.swift | Refactors refresh-token token fetching to use a shared buildFetchTokenPayload that handles organization URNs and explicit organization IDs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Tests/LogtoClientTests/LogtoClient/LogtoClientTests+AccessToken.swift
Outdated
Show resolved
Hide resolved
70f4b51 to
2997fc7
Compare
2997fc7 to
b46ae99
Compare
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.
Summary
LogtoClient(resource + organization, plus “claims” variants)getAccessToken(for:organizationId:): Returns an access token forresource(optional) andorganizationId(optional). Uses cached token if valid; otherwise refreshes.getAccessTokenClaims(for:organizationId:): Returns decoded access token claims forresourceandorganizationId.getOrganizationToken(forId:): Returns an organization-scoped access token forid.getOrganizationTokenClaims(forId:): Returns decoded organization token claims forid.Testing
test cases added/updated