Skip to content

Conversation

@sanchitmehta94
Copy link
Contributor

@sanchitmehta94 sanchitmehta94 commented Dec 8, 2025

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

📋 Changes

SDK-7259

Swift 6 support · Issue #890 · auth0/Auth0.swift

As per this github issue we need to conform Credential Manager conform to Sendable. so that that can be called from clients within actors when using Swift 6 without any errors.

Swift 6 support · Issue #890 · auth0/Auth0.swift

Even the original ask that came on community page was to conform Credential Manager to Sendable
CredentialsManager.credentials and sendability

The goal of this PR is to ensure that all public interfaces exposed to clients conform to Sendable, so they remain usable both in legacy callback workflows and in modern Swift concurrency contexts.

This also addresses a real issue reported by customers: using CredentialManager inside an actor with the Swift 6 compiler produced errors because CredentialManager did not conform to Sendable. This PR resolves that problem by making the necessary types explicitly Sendable while maintaining full backward compatibility with the current SDK architecture.

Follow up PR: As our customers are trying to access Credential Managers within actors . we would imitate the same behavior in the sample app.

We haven’t migrated the SDK to strict Swift concurrency (e.g., actors, async/await-based APIs). Doing so would be a major undertaking and a breaking change that affects the entire codebase, and we also need to remain backward-compatible with existing callback-based APIs.

📎 References

🎯 Testing

For testing as Auth0.swift is compiled with Swift 5 it would not throw errors for testing we should look if there are are no warning realted to sendability in Credential Manager file.

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 adds Sendable conformance to CredentialsManager and related types to enable Swift 6 compatibility, allowing these types to be safely used within actors and across concurrency boundaries without compiler errors.

  • Added Sendable conformance to key public types including CredentialsManager, Authentication, CredentialsStorage, Telemetry, BiometricPolicy, and BioAuthentication
  • Used @unchecked Sendable for BiometricSession with proper thread-safe lock-based synchronization
  • Applied @preconcurrency imports for external frameworks that don't yet conform to Sendable (JWTDecode, LocalAuthentication)

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Auth0/Telemetry.swift Added Sendable conformance to the Telemetry struct
Auth0/Requestable.swift Removed unused Combine import
Auth0/IDTokenValidator.swift Added @preconcurrency import for JWTDecode to suppress Sendable warnings
Auth0/CredentialsStorage.swift Added Sendable conformance to the CredentialsStorage protocol
Auth0/CredentialsManager.swift Added Sendable conformance to CredentialsManager and marked BiometricSession as @unchecked Sendable with thread-safe lock usage
Auth0/BiometricPolicy.swift Added Sendable conformance to the BiometricPolicy enum
Auth0/BioAuthentication.swift Added Sendable conformance and @preconcurrency import for LocalAuthentication
Auth0/Authentication.swift Added Sendable conformance to the Authentication protocol

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pmathew92
Copy link
Contributor

@claude

@github-actions

This comment has been minimized.

github-actions[bot]

This comment was marked as outdated.

@sanchitmehta94 sanchitmehta94 force-pushed the feature/SendableConformation branch from e354332 to 8d9ffa2 Compare December 8, 2025 12:09
Copy link
Contributor Author

@sanchitmehta94 sanchitmehta94 left a comment

Choose a reason for hiding this comment

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

import Auth0

// MARK: - Swift 6 Sendability Test: CredentialsManager in Actor
actor AuthService {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for testing the changes please run the App Target should compile successfully.
I am thinking to add a follow up PR to create a separate target for Swift6Testing

PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

App Target is moved to use Swift version: 6.0


func fetchCredentials() async throws -> Credentials {
// This method can be called across concurrency contexts eg. Actor
return try await credentialsManager.credentials(withScope: "openid profile email",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

#890 (comment)
that is the ask from customer to be able toc all this API within actor when code being compiled with Swift 6.

@sanchitmehta94 sanchitmehta94 self-assigned this Dec 9, 2025
@sanchitmehta94 sanchitmehta94 force-pushed the feature/SendableConformation branch from 4a27e2c to 1ae38a2 Compare December 9, 2025 10:24
@sanchitmehta94 sanchitmehta94 added the review:medium Medium review label Dec 9, 2025
public struct CredentialsManager: Sendable {

// storage is inherently sendable as it uses Keychain under the hood and is stateless
private let sendableStorage: SendableBox<CredentialsStorage>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have used SendableBox instead of conforming to Sendable protocol to keep it backward compatible and let the change go in minor release which is fine as it is sendable by design

@pmathew92
Copy link
Contributor

@claude

@github-actions
Copy link

github-actions bot commented Dec 10, 2025

Claude finished @pmathew92's task —— View job


Overall Assessment

❌ This PR has critical issues that must be addressed before merging. While the goal of adding Sendable conformance for Swift 6 support is sound, the implementation has several bugs and unsafe patterns that will prevent compilation or cause thread-safety issues.

Critical Issues

  1. Compilation Error in CredentialsManager.swift:66 - The initializer assigns storage to self.storage, but storage is now a computed property. This needs to wrap the parameter: self.sendableStorage = SendableBox(value: storage)

  2. Missing Sendable Conformance for CredentialsStorage Protocol - The CredentialsStorage protocol must conform to Sendable. Without this, wrapping it in @unchecked Sendable via SendableBox is unsafe because custom implementations aren't guaranteed to be thread-safe.

  3. Mutable Property Violates Sendable - The bioAuth property is declared as var in a Sendable struct, which violates Swift's Sendable safety guarantees. This needs to be immutable or properly synchronized.

Additional Concerns

  • The SendableBox comment in Shared.swift is misleading about thread-safety guarantees
  • The documentation in EXAMPLES.md doesn't adequately explain the difference between Sendable conformance and thread-safety
  • The test code in App/ViewController.swift has potential lifecycle issues with the detached Task

Security & Performance

No significant security or performance concerns beyond the thread-safety issues noted above. The lock-based synchronization for BiometricSession appears correct.


pmathew92
pmathew92 previously approved these changes Dec 10, 2025
Copy link
Contributor

@pmathew92 pmathew92 left a comment

Choose a reason for hiding this comment

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

LGTM

@sanchitmehta94 sanchitmehta94 enabled auto-merge (squash) December 10, 2025 11:59
NandanPrabhu
NandanPrabhu previously approved these changes Dec 10, 2025
@sanchitmehta94 sanchitmehta94 force-pushed the feature/SendableConformation branch from 7552b9b to 12c0878 Compare December 11, 2025 13:00
import Auth0

// MARK: - Swift 6 Sendability Test: CredentialsManager in Actor
actor AuthService {
Copy link
Contributor Author

@sanchitmehta94 sanchitmehta94 Dec 11, 2025

Choose a reason for hiding this comment

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

ideally this code should not impact test cases as they run on test targets rather than App target but somehow this was impacting them would raise a separate PR we do have plan to ass swift 6 test target

@sanchitmehta94 sanchitmehta94 merged commit 480c543 into master Dec 11, 2025
13 of 14 checks passed
@sanchitmehta94 sanchitmehta94 deleted the feature/SendableConformation branch December 11, 2025 13:32
@NandanPrabhu NandanPrabhu mentioned this pull request Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:medium Medium review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants