* fix #203 NetworkTransport race, with main-isolated variables (#206) Co-authored-by: wti <wti@users.noreply.github.com> * feat/auth: Authentication implementation (#205) * feat: added authentication * feat(auth): improvement to error handling * feat(auth): updated errors and tests in OAuthClientRegistrar * feat(auth): updated ci conformance package version * feat(auth): bumped node version * feat(auth): updated ci conformance step * feat(auth): improvement to Linux support * chore: added docc plugin * chore: added spi yml * chore: added documentation step to ci * chore: increased timeout for test from 5 to 10m --------- Co-authored-by: Paal Øye-Strømme <paal.o.eye@gmail.com> Co-authored-by: wti <wti@users.noreply.github.com> Co-authored-by: yehorsobko <yehorsobko@macpaw.com>
37 lines
1,012 B
Swift
37 lines
1,012 B
Swift
import Foundation
|
|
|
|
// MARK: - Token Storage Protocol
|
|
|
|
/// Abstraction for persisting OAuth access tokens.
|
|
///
|
|
/// Implement this protocol to provide custom token storage (e.g., Keychain-backed).
|
|
/// The default ``InMemoryTokenStorage`` stores tokens in memory only.
|
|
public protocol TokenStorage: AnyObject, Sendable {
|
|
func save(_ token: OAuthAccessToken)
|
|
func load() -> OAuthAccessToken?
|
|
func clear()
|
|
}
|
|
|
|
// MARK: - In-Memory Implementation
|
|
|
|
/// Default ``TokenStorage`` that stores the access token in memory only.
|
|
///
|
|
/// The token is lost when the process exits. For persistent storage
|
|
/// (e.g., system Keychain), implement ``TokenStorage`` directly.
|
|
public final class InMemoryTokenStorage: TokenStorage, @unchecked Sendable {
|
|
private var token: OAuthAccessToken?
|
|
|
|
public init() {}
|
|
|
|
public func save(_ token: OAuthAccessToken) {
|
|
self.token = token
|
|
}
|
|
|
|
public func load() -> OAuthAccessToken? {
|
|
token
|
|
}
|
|
|
|
public func clear() {
|
|
token = nil
|
|
}
|
|
}
|