-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include new async / await language feature to make parallel executions possible #6
Conversation
…nt functionaity. Also added unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- All async protocol requirements should be converted to protocol extensions that calls the original function with a continucation in order to maintain backward compatibility.
- Remove the
Async
suffix from all method names, because it is redundant with theasync
keyword. - All async functions should not return Optional value just because the completion handler return an Optional - that's because the completion handlers return either the result or an error. For async functions they should either throw an error or return non-optional result. The only exception from that case would be where the Optional value make sense and is valid result.
- All async test functions that calls throwing code should be made
throws
, so there will be no need to force unwrap errors.
@@ -17,6 +17,9 @@ public protocol CredentialsProvider { | |||
///Provides credentials in an asynchronous manner. Can be implemented in a way to show a login screen. | |||
func credentials(handler: @escaping (Username, Password) -> Void) | |||
|
|||
@available(iOS 13, tvOS 13.0.0, macOS 10.15, *) | |||
func credentialsAsync() async -> (Username, Password) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be a protocol requirement, but a protocol extension with the implementation.
Remove the Async
suffix from the method name.
These should be applied to all similar cases.
@@ -61,6 +70,14 @@ extension IdentityManager { | |||
handler?(error) | |||
} | |||
} | |||
|
|||
@available(iOS 13, tvOS 13.0.0, macOS 10.15, *) | |||
public func forceAuthenticateAsync() async throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directly call the respective forceAuthenticate
using a continuation.
@@ -63,6 +63,23 @@ open class DefaultAccessTokenRefresher: AccessTokenRefresher { | |||
} | |||
} | |||
} | |||
|
|||
@available(iOS 13, tvOS 13.0.0, macOS 10.15, *) | |||
open func refreshAsync(using requestModel: AccessTokenRefreshRequest) async throws -> AccessTokenResponse? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result should not be optional. It should throw an error (eg. MHIdentityKitError.Reason.invalidAccessTokenResponse
) if there is no AccessTokenResponse
.
This should be applied to all similar cases.
|
||
let manager = OAuth2IdentityManager(flow: Flow(e: XCTestExpectation(description: "XCTestCase Default Expectation")), refresher: Refresher(e: XCTestExpectation(description: "XCTestCase Default Expectation")), storage: InMemoryIdentityStorage(), authorizationMethod: .header) | ||
|
||
let request1 = try! await manager.authorizeAsync(request: URLRequest(url: URL(string: "http://foo.bar")!), forceAuthenticate: false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the test function throwing, so there will be no need to force unwrap the error.
This should be applied to all similar cases.
…ix from all method names, async functions do not return optional value just because the handler does it, async test functions calling throwing code marked as throwing.
MHIdentityKit/Infrastructure/CredentialsProvider/AnyCredentialsProvider.swift
Outdated
Show resolved
Hide resolved
MHIdentityKit/Infrastructure/CredentialsProvider/CredentialsProvider.swift
Outdated
Show resolved
Hide resolved
MHIdentityKit/Infrastructure/IdentityManager/IdentityManager.swift
Outdated
Show resolved
Hide resolved
MHIdentityKit/Infrastructure/IdentityManager/IdentityManager.swift
Outdated
Show resolved
Hide resolved
MHIdentityKit/OAuth2/Flows/ResourceOwnerPasswordCredentialsGrantFlow.swift
Outdated
Show resolved
Hide resolved
MHIdentityKit/OAuth2/Flows/ResourceOwnerPasswordCredentialsGrantFlow.swift
Outdated
Show resolved
Hide resolved
MHIdentityKit/OAuth2/Flows/ResourceOwnerPasswordCredentialsGrantFlow.swift
Outdated
Show resolved
Hide resolved
MHIdentityKit/OAuth2/Flows/ResourceOwnerPasswordCredentialsGrantFlow.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add documentation to each new function.
@@ -11,73 +11,74 @@ import Foundation | |||
import XCTest | |||
@testable import MHIdentityKit | |||
|
|||
@available(iOS 13, tvOS 13.0.0, macOS 10.15, *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should not be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So to bring it back as it was before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i have no idea why you changed that test.
No description provided.