77
88import AuthenticationServices
99
10- /// Describes the error reason for a failed `AuthenticationSession `
10+ /// Describes the error reason for a failed `WebServiceAuthentication `
1111///
12- /// - userCanceled: The user cancelled the authentication session
13- /// -
12+ /// - userCanceled: The user cancelled the authentication session.
13+ /// - failed: The authentication failed for some reason.
14+ /// - invalidResponse: The response returned by the web service was invalid.
15+ /// - notHandled: The error wasn't handled by the web service.
16+ /// - presentationContextInvalid: The presentation content provided was invalid.
17+ /// - unknown: Some unknown error ocurred when authenticating with the web service.
1418enum AuthenticationError : Error {
1519 case userCanceled
1620 case failed
@@ -20,18 +24,42 @@ enum AuthenticationError: Error {
2024 case unknown
2125}
2226
27+ /// Describes a generic method of authenticating with a service
2328protocol ServiceAuthentication {
29+ /// The parameters to pass to authenticate with the service
2430 associatedtype Parameters
31+ /// The object type on a successful service authentication
2532 associatedtype Completion
33+ /// THe error type on a non-successful service authentication
2634 associatedtype ErrorType : Error
2735
36+ /// Describes a closure that gets invoked on success/failure of a service authentication
2837 typealias AuthenticationSessionClosure = ( ( Result < Completion , ErrorType > ) -> Void )
2938
39+ /// Starts the service authentication.
40+ /// - Parameters:
41+ /// - parameters: An instance of `Parameters` which can be used in authenticating against the service.
42+ /// - completionHandler: The closure to invoke on a success or failure response from the service.
43+ /// - Returns: A `Bool` value as to whether or not the service authentication was started or not.
3044 func start( with parameters: Parameters , completionHandler: @escaping AuthenticationSessionClosure ) -> Bool
45+
46+ /// Cancels the service authentication.
3147 func cancel( )
3248}
3349
50+ /// A basic OAuth web service authentication object.
3451class WebServiceAuthentication : ServiceAuthentication {
52+
53+ /// The parameters used when authenticating against a web service
54+ struct WebServiceAuthenticationParameters {
55+ /// The URL to use in authenticating the service
56+ let url : URL
57+ /// The callback url scheme which the service uses to pass back any data
58+ let callbackURLScheme : String ?
59+ /// Determines whether or not the session should be ephemeral or not. Not all service authentication types support this
60+ let prefersEphemeralWebBrowserSession : Bool
61+ }
62+
3563 typealias Parameters = WebServiceAuthenticationParameters
3664 typealias Completion = URL
3765 typealias ErrorType = AuthenticationError
@@ -46,8 +74,3 @@ class WebServiceAuthentication: ServiceAuthentication {
4674 }
4775}
4876
49- struct WebServiceAuthenticationParameters {
50- let url : URL
51- let callbackURLScheme : String ?
52- let prefersEphemeralWebBrowserSession : Bool
53- }
0 commit comments