Skip to content

Comments

feat: add access token methods#144

Merged
gao-sun merged 4 commits intomasterfrom
gao-access-token-methods
Jan 25, 2026
Merged

feat: add access token methods#144
gao-sun merged 4 commits intomasterfrom
gao-access-token-methods

Conversation

@gao-sun
Copy link
Member

@gao-sun gao-sun commented Jan 25, 2026

Summary

  • add access token helpers to LogtoClient (resource + organization, plus “claims” variants)
    • getAccessToken(for:organizationId:): Returns an access token for resource (optional) and organizationId (optional). Uses cached token if valid; otherwise refreshes.
    • getAccessTokenClaims(for:organizationId:): Returns decoded access token claims for resource and organizationId.
    • getOrganizationToken(forId:): Returns an organization-scoped access token for id.
    • getOrganizationTokenClaims(forId:): Returns decoded organization token claims for id.
  • implement underlying fetch / utilities for token exchange and parsing
  • expand SwiftUI demo with placeholder-based config + buttons to fetch access/organization token claims

Testing

test cases added/updated

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.decodeAccessToken and JsonValue convenience accessors to work with structured access token claims.
  • Extend LogtoClient access 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 via buildFetchTokenPayload, 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.

@gao-sun gao-sun force-pushed the gao-access-token-methods branch 3 times, most recently from 70f4b51 to 2997fc7 Compare January 25, 2026 06:49
@gao-sun gao-sun force-pushed the gao-access-token-methods branch from 2997fc7 to b46ae99 Compare January 25, 2026 06:55
@gao-sun gao-sun marked this pull request as ready for review January 25, 2026 07:49
@gao-sun gao-sun merged commit b50ab83 into master Jan 25, 2026
3 checks passed
@gao-sun gao-sun deleted the gao-access-token-methods branch January 25, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

1 participant