AuthenticationManager
public class AuthenticationManager
AuthenticationManager manages the overall authentication, authorization, and deauthentication process.
It does this by determining what type of authentication is needed based on the current system state and the provided configuration, and then passes detailed authentication tasks to AuthenticationHandler modules. Each implementer of the AuthenticationHandler protocol should implement one type of authentication.
In this way, based on configuration, AuthenticationManager will automatically handle online and offline authentication and if so configured will utilize biometric authentication (Touch ID or Face ID) for subsequent authentications after an initial online login was performed successfully.
Example:*
// First, create and populate our configuration
var config = AuthenticationManagerConfiguration()
let url = URL(string: "https://auth.myserver.com")
config.baseURL = url
config.clientId = "my_oauth_client_id"
config.clientSecret = "my_oauth_client_secret"
config.useBiometricAuthentication = true // BiometricAuthentication for refresh and offline authentication is disabled by default.
// Next, create an AuthenticationManager object with the configuration
let manager = AuthenticationManager(configuration: config)
// Assign an OnlineAuthenticationHandler or subclass. In this case, UAABrowserAuthenticationHandler provides support for browser-based UAA login
let onlineHandler = UAABrowserAuthenticationHandler(redirectURI: "predixmobile://foobar")
// Assign a refresh handler to allow for refreshing a token without having to do a full login again
onlineHandler.refreshAuthenticationHandler = UAARefreshAuthenticationHandler()
// Set delegates as needed
onlineHandler.authenticationBrowserDelegate = self
// Assign the OnlineAuthenticationHandler to the manager
manager.onlineAuthenticationHandler = onlineHandler
// Similarly, assign an OfflineAuthenticationHandler for offline authentication support
manager.offlineAuthenticationHandler = OfflineAuthenticationHandler()
// And assign an AuthorizationHandler class for calling the authorization service after authenticating.
manager.authorizationHandler = PredixSyncAuthorizationHandler()
// Then call authenticate. The completionHandler will be called when the authentication process finishes.
manager.authenticate { (status) in
print("Authentication Status: \(status)")
}
-
Authentication completion status enumeration
returns information about the authentication state when the
See moreauthenticate(completionHandler:)
method completed.Declaration
Swift
public enum AuthenticationCompletionStatus
-
The uaaAccessToken that was received from a successful UAA authentication
Declaration
Swift
public internal(set) var uaaAccessToken: PredixUAAAccessToken?
-
Initializes and returns an AuthenticationManager object with the provided configuration
- configuration: Configuration for this manager
Declaration
Swift
required public init(configuration: AuthenticationManagerConfiguration)
-
The
AuthenticationHandler
that processes authentication requests while online.See also:
OnlineAuthenticationHandler
Declaration
Swift
public var onlineAuthenticationHandler: OnlineAuthenticationHandler?
-
The
AuthenticationHandler
that processes authentication requests while offline.See also:
OfflineAuthenticationHandler
Declaration
Swift
public var offlineAuthenticationHandler: OfflineAuthenticationHandler?
-
The
AuthorizationHandler
object that processes authorization after a user has been authenticated.See also:
AuthorizationHandler
Declaration
Swift
public var authorizationHandler: AuthorizationHandler?
-
AuthenticationManagerConfiguration
Declaration
Swift
public internal(set) var configuration: AuthenticationManagerConfiguration
-
true during the authentication process
Declaration
Swift
public var isAuthenticationInProgress: Bool
-
Starts the authentication/authorization process.
- completionHandler: closure called when authentication/authorization has completed.
- status:
AuthenticationCompletionStatus
: status of the completed authentication process
Declaration
Swift
public func authenticate(completionHandler: @escaping (_ status: AuthenticationCompletionStatus) -> Void)
-
Cancels an authentication in-process. Does nothing if no authentication is currently in process.
Declaration
Swift
public func cancelAuthentication()
-
Logs user out of the system, by calling the Logout methods on the manager’s
onlineAuthenticationHandler
andofflineAuthenticationHandler
Then also, clears the UserManager’s authorized user information, and clears any session cookies from shared
HTTPCookieStorage
.Declaration
Swift
public func logout(completionHandler: @escaping () -> Void)
Parameters
completionHandler
closure called when logout has completed.