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 Touch 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.useTouchID = true // TouchId 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 = PredixMobileAuthorizationHandler()

// Then call authenticate. The completionHandler will be called when the authentication process finishes.
manager.authenticate { (status) in
    print("Authentication Status: \(status)")
}
  • 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 and offlineAuthenticationHandler

    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.