-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support generalised OAuth 2.1 clients (#92)
* WIP * WIP * WIP * chore: Working Spotify oauth client * chore: Adds credential hooks * chore: remove conditional compilation * feat: Improved OAuth delegate & proxy * feat: supports for sign in & out via proxy * chore: restore 5.9 tools version * chore: fix test imports * feat: StandardOAuthSystem * chore: Add unit tests for standard system * chore: fix package & test * chore: Add test for OAuth Proxy * chore: more OAuth tests * chore: Testing --------- Co-authored-by: danthorpe <[email protected]>
- Loading branch information
Showing
42 changed files
with
1,555 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Foundation | ||
|
||
package struct AnySendable: @unchecked Sendable { | ||
package let base: Any | ||
package init<Base: Sendable>(_ base: Base) { | ||
self.base = base | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
|
||
package struct ErrorMessage: Error, Equatable, ExpressibleByStringLiteral { | ||
let message: String | ||
package init(message: String) { | ||
self.message = message | ||
} | ||
package init(stringLiteral value: String) { | ||
self.init(message: value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
Sources/Networking/Components/Authentication/Delegates/AnyAuthenticationDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
|
||
package actor AnyAuthenticationDelegate<Credentials: AuthenticatingCredentials>: AuthenticationDelegate { | ||
package let delegate: any AuthenticationDelegate<Credentials> | ||
|
||
package init(delegate: some AuthenticationDelegate<Credentials>) { | ||
self.delegate = delegate | ||
} | ||
|
||
package func authorize() async throws -> Credentials { | ||
try await delegate.authorize() | ||
} | ||
|
||
package func refresh(unauthorized: Credentials, from response: HTTPResponseData) async throws -> Credentials { | ||
try await delegate.refresh(unauthorized: unauthorized, from: response) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Sources/Networking/Components/Authentication/Delegates/StreamingAuthenticationDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Foundation | ||
|
||
package actor StreamingAuthenticationDelegate<Delegate: AuthenticationDelegate>: AuthenticationDelegate { | ||
package let delegate: Delegate | ||
private let (stream, continuation) = AsyncStream<Delegate.Credentials>.makeStream() | ||
|
||
package var credentials: AsyncStream<Delegate.Credentials> { | ||
stream.shared().eraseToStream() | ||
} | ||
|
||
package init(delegate: Delegate) { | ||
self.delegate = delegate | ||
} | ||
|
||
package func authorize() async throws -> Delegate.Credentials { | ||
let credentials = try await delegate.authorize() | ||
continuation.yield(credentials) | ||
return credentials | ||
} | ||
|
||
package func refresh(unauthorized: Delegate.Credentials, from response: HTTPResponseData) async throws | ||
-> Delegate.Credentials | ||
{ | ||
let credentials = try await delegate.refresh(unauthorized: unauthorized, from: response) | ||
continuation.yield(credentials) | ||
return credentials | ||
} | ||
} |
Oops, something went wrong.