ServiceBasedAuthenticationHandler

open class ServiceBasedAuthenticationHandler: OnlineAuthenticationHandler, CallAuthenticationServiceProtocol

OnlineAuthenticationHandler subclass for handling service-call based based (non-browser) online authentication.

Handles making a request to the backend for authentication, and parsing the results.

  • Delegate used to retrieve user credentials, and communicate service call failures.

    See also: ServiceBasedAuthenticationHandlerDelegate

    -SeeAlso: ServiceBasedAuthenticationHandlerDelegate

    Declaration

    Swift

    public weak var authenticationServiceDelegate: ServiceBasedAuthenticationHandlerDelegate?
  • URLSessionConfiguration to use for the authentication request. Defaults to URLSessionConfiguration.default.

    Declaration

    Swift

    public var sessionConfiguration = URLSessionConfiguration.default
  • Response status code expected from the server if the authentication request was successful.

    Declaration

    Swift

    public var serviceCallSucceededResponseCode = Http.StatusCode.ok
  • Response status code expected from the server if the authentication request was unsuccessful.

    Declaration

    Swift

    public var serviceCallFailedResponseCode = Http.StatusCode.unauthorized
  • The key used to provide the user name in the authentication request body.

    Declaration

    Swift

    public var usernameRequestPayloadKey = "username"
  • The key used to provide the password in the authentication request body.

    Declaration

    Swift

    public var passwordRequestPayloadKey = "password"
  • Request headers to add to the authentication request

    Declaration

    Swift

    public var requestHeaders: [String: String] = [:]
  • The body encoding to use in the authentication request

    See also: RequestBodyEncoding

    -SeeAlso: RequestBodyEncoding

    Declaration

    Swift

    public var requestBodyEncoding: RequestBodyEncoding
  • Initializes and returns a ServiceBasedAuthenticationHandler object

    Declaration

    Swift

    public override init()
  • Not expected to be called from external consumers.

    Subclasses may override this method to provide additional functionality prior to the authentication process.

    Performs the online service-based authentication process, calling the authenticationServiceDelegate to gather the user’s credentials.

    Declaration

    Swift

    override open func performOnlineAuthentication()
  • Should not be called from external consumers. The authenticate method should be used to start the authentication process.

    Accepts the user’s offline credentials as provided by the ServiceBasedAuthenticationHandlerDelegate and performs offline authentication.

    Default behavior will validate the provided credentials, and call the ServiceBasedAuthenticationHandlerDelegate‘s authenticationHandlerProvidedCredentialsWereInvalid method prior to re-calling the authenticationHandler(, provideCredentialsWithCompletionHandler:) method.

    Subclasses may override this method to provide extra processing/validation of the user’s credentials, prior to calling super.performAuthentication(userName: , password: ) or could modify the actual work of online authentication, in which case they should call authenticationComplete(status:) with the result of that authentication.

    Declaration

    Swift

    open func performAuthenticationRequest(userName: String, password: String)
  • Not expected to be called from external consumers.

    Subclasses may override this method to provide additional information into the authentication request service call body.

    Declaration

    Swift

    open func createAuthenticationRequestPayload(userName: String, password: String) -> [String: String]
  • Not expected to be called from external consumers.

    Encodes the request body payload based on the configured requestBodyEncoding. Can be overriden to allow subclasses to support additional encodings, or otherwise alter the refresh service call process.

    See also: RequestBodyEncoding

  • payload: Dictionary containing the key/value pairs that make up the body of the refresh request payload.

  • See also

    RequestBodyEncoding

    Declaration

    Swift

    open func encodeRequestPayload(_ payload: [String: String]) -> Data?
  • Creates the URLSession used during login and logout calls

    If overridden, subclasses should also override cancelAuthentication to cancel tasks associated with the session created here.

    Declaration

    Swift

    open func createSession() -> URLSession