AgsAuth

open class AgsAuth

AeroGear Services Auth SDK

Allows users to perform login/logout actions against an Keycloak service provisioned by the AeroGear mobile service on OpenShift.

### Example ### initialise the authentication configuration service and configure the Auth SDK

 let authConfig = AuthenticationConfig(redirectURL: "com.youapp://callback")
 AgsAuth.instance.configure(authConfig: authConfig)

Login using the configured Auth SDK

 AgsAuth.instance.login()
  • instance of the Auth SDK

    Declaration

    Swift

    public static let instance: <<error type>>
  • Errors generated by the auth module

    See more

    Declaration

    Swift

    public enum Errors : Error
  • Configure the Auth SDK.

    Important

    This function should be called before any other functions are invoked. Only need to call this once.

    Throws

    a noServiceConfigurationFound error if no authentication configuration was found in the mobileConfig used to initialise the Auth SDK

    Declaration

    Swift

    public func configure(authConfig: AuthenticationConfig) throws

    Parameters

    authConfig

    Configuration options for the auth module

  • Perform user login action.

    Throws

    a serviceNotConfigured error if the Auth SDK has not been configured

    Declaration

    Swift

    public func login(presentingViewController: UIViewController, onCompleted: @escaping (_ user: User?, _ error: Error?) -> Void) throws

    Parameters

    presentingViewController

    the ViewController that initiates the login process

    onCompleted

    callback function that will be invoked when the login is finished

    user

    the user returned in the onCompleted callback function. Will be nil if login failed

    error

    the error returned in the onCompleted callback function. Will be nil if login was successful

  • Resume the authentication process.

    This function should be invoked when the user has finished logging in via the browser and redirected back to the app that started the login.

    Throws

    a serviceNotConfigured error if the Auth SDK has not been configured

    Declaration

    Swift

    public func resumeAuth(url: URL) throws -> Bool

    Parameters

    url

    The redirect url passed backed from the login process

    Return Value

    true if the login process can be resumed, false otherwise

  • Perform the logout action.

    Throws

    a serviceNotConfigured error if the Auth SDK has not been configured or a noLoggedInUserError if no user is logged in

    Declaration

    Swift

    public func logout(onCompleted: @escaping (_ error: Error?) -> Void) throws

    Parameters

    onCompleted

    callback function that will be invoked when the logout process has completed

    error

    the serviceNotConfigured error returned in the onCompleted callback function

  • Get the current logged in user.

    Throws

    a serviceNotConfigured error if the Auth SDK has not been configured

    Declaration

    Swift

    public func currentUser() throws -> User?

    Return Value

    the user that is currently logged in