Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 0 additions & 183 deletions Sources/OAuthKit/Keychain/Keychain+Storage.swift

This file was deleted.

93 changes: 0 additions & 93 deletions Sources/OAuthKit/Keychain/Keychain.swift

This file was deleted.

3 changes: 3 additions & 0 deletions Sources/OAuthKit/OAuth+Option.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ public extension OAuth.Option {
/// This is disabled by default, but this can be turned on to allow developers to use an ephemeral webkit datastore
/// that effectively implements private browsing and forces a new login attempt every time an authorization flow is started.
static let useNonPersistentWebDataStore: OAuth.Option = .init(rawValue: "useNonPersistentWebDataStore")

/// A key used for providing a custom token storage.
static let storage: OAuth.Option = .init(rawValue: "storage")
}

69 changes: 69 additions & 0 deletions Sources/OAuthKit/OAuth+Storage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// OAuth+Storage.swift
// OAuthKit
//
// Created by Kevin McKee
//

import Foundation

/// The default token identifier suffix.
private let tokenIdentifier = "oauth-token"

extension OAuth {

// Provides the storage protocols used for storing token data.
// The storage operations should all be wrapped in a locking
// mechanism to prevent any potential data races.
public protocol Storage: Sendable {

/// The owning account identifier.
/// - Parameter account: a key indicating the account owner. Ideally, use the application identifier for this value.
init(_ account: String)

/// The account owner of this token storage.
var account: String { get }

/// Returns a list of keys owned by this account.
var keys: [String] { get }

/// Sets the data for the specified key
/// - Parameters:
/// - value: the value to store for the specified key
/// - key: the key to use for the data
/// - Returns: true if able to set the data, otherwise false
@discardableResult
func set(_ value: Codable, for key: String) throws -> Bool

/// Fetches storeed data from the storage with the specified key.
/// - Parameter key: the keychain key
/// - Returns: the data for the specified key or nil if not found
func get<T>(key: String) throws -> T? where T: Codable

/// Deletes the value for the specified key.
/// - Parameter key: the key to delete
/// - Returns: true if able to delete from the storage, otherwise false
@discardableResult
func delete(key: String) -> Bool

/// Clears all values and keys for the current account.
/// - Returns: true if values were cleared, otherwise false.
@discardableResult
func clear() -> Bool

/// Builds the combined account key by prefixing the specified key with the account.
/// - Parameter key: the key to prefix.
/// - Returns: the unique account key to use
func accountKey(_ key: String) -> String
}
}

public extension OAuth.Storage {

/// Builds the combined account key by prefixing the specified key with the account.
/// - Parameter key: the key to prefix.
/// - Returns: the unique account key to use
func accountKey(_ key: String) -> String {
account + "." + key + "." + tokenIdentifier
}
}
Loading
Loading