V0.12.x (#215)
* 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>
This commit is contained in:
parent
973b46b8f7
commit
6132fd4b5b
1 changed files with 10925 additions and 199 deletions
37
Sources/MCP/Base/Authorization/TokenStorage.swift
Normal file
37
Sources/MCP/Base/Authorization/TokenStorage.swift
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue