AuthClient

public class AuthClient : IAuthClient, Equatable

Internal implementation of IAuthClient protocol

private methods

  • Performs common steps for different authorization types.

    Declaration

    Swift

    private func performAuthorization(_ type: FlowType, viewController: UIViewController, completion: @escaping (Result<AnyObject, Error>) -> Void)

    Parameters

    type

    Specifies authorization type which is used on the next step.

    viewController

    The UIViewController to present auth flow request.

    completion

    The callback to invoke upon request completion.

  • Calls the appropriate method based on the flow type.

    Declaration

    Swift

    private func authorize(type: FlowType, configuration: OIDServiceConfiguration, redirectUri: URL, viewController: UIViewController, completion: @escaping (Result<AnyObject, Error>) -> Void)

    Parameters

    type

    Specifies authorization type which is used to determine the specific method for the each flow.

    configuration

    Service configuration obtained for specified domain.

    redirectUri

    URL created from the [Config] member.

    viewController

    The UIViewController to present auth flow request.

    completion

    The callback to invoke upon request completion.

  • Undocumented

    Declaration

    Swift

    private func doAuthorizationForAuthCodeFlow(configuration: OIDServiceConfiguration, redirectUri: URL, viewController: UIViewController, completion: @escaping (Result<AnyObject, Error>) -> Void)
  • Replaces the ‘#’ characters to ‘?’ in the string and creates URL from it. ASWebAuthenticationSession gives us the URL with ‘#’ character inside and the OIDURLQueryComponent object can’t be created from this url. To be able to create OIDURLQueryComponent object we need to replace this character.

    Declaration

    Swift

    private func modifyUrl(_ url: URL) -> URL?

    Parameters

    url

    URL to obtain string for modification.

    Return Value

    Modified URL

  • Performs validation of the authorization response obtained via the AppAuth framework.

    Declaration

    Swift

    private func validateResponse(_ response: OIDAuthorizationResponse?) -> (OIDAuthorizationResponse?, NSError?)

    Parameters

    response

    Response to validate.

    Return Value

    Response object and nil as error on success or nil as responce and error on failure.

  • Creates authorization response.

    Declaration

    Swift

    private func createAuthResponse(url: URL, request: OIDAuthorizationRequest) -> (OIDAuthorizationResponse?, NSError?)

    Parameters

    url

    URL to obtain parameters for response creation.

    request

    Request object which is used for response creation.

    Return Value

    Response object and nil as error on success or nil as responce and error on failure.

  • Presents hybrid flow authorization request.

    Declaration

    Swift

    private func presentRequest(_ request: OIDAuthorizationRequest, userAgent: OIDExternalUserAgentIOS, authorizationSession: OIDAuthorizationSession, viewController: UIViewController, completion: @escaping (Result<AnyObject, Error>) -> Void)

    Parameters

    request

    Request to be presented.

    userAgent

    Agent which takes part in request presentation.

    authorizationSession

    Session that should be stored in case of success response.

    viewController

    The UIViewController to present hybrid flow request.

    completion

    The callback to invoke upon request completion.

  • Performs authorization for the hybrid flow.

    Declaration

    Swift

    private func doAuthorizationForHybridFlow(configuration: OIDServiceConfiguration, redirectUri: URL, viewController: UIViewController, completion: @escaping (Result<AnyObject, Error>) -> Void)

    Parameters

    configuration

    Service configuration obtained for specified domain.

    redirectUri

    URL created from the [Config] member.

    viewController

    The UIViewController to present auth flow request.

    completion

    The callback to invoke upon request completion.

  • Performs access token request.

    Declaration

    Swift

    private func doAccessTokenRequest(configuration: OIDServiceConfiguration, redirectUri: URL, completion: @escaping (Result<AnyObject, Error>) -> Void)

    Parameters

    configuration

    Service configuration obtained for specified domain.

    redirectUri

    URL created from the [Config] member.

    viewController

    The UIViewController to present auth flow request.

    completion

    The callback to invoke upon request completion.

  • Performs authorization code flow.

    Declaration

    Swift

    private func doAuthWithoutCodeExchange(configuration: OIDServiceConfiguration, redirectUri: URL, clientID: String, clientSecret: String?, scopes: [String], viewController: UIViewController, completion: @escaping (Result<AnyObject, Error>) -> Void)

    Parameters

    configuration

    Service configuration obtained for specified domain.

    redirectUri

    URL created from the [Config] member.

    viewController

    The UIViewController to present auth flow request.

    completion

    The callback to invoke upon request completion.

  • Performs saving auth state to the secure storage. If the secure storage usage set to false during the [AuthClient] object creation, then authState object won’t be stored because the keychainStorage property of the [AuthClient] is nil.

    Declaration

    Swift

    private func saveToSecureStorage(authState: AnyObject)

    Parameters

    authState

    Auth state to be stored in secure storage.

  • Performs removing auth state from the secure storage.

    Declaration

    Swift

    private func removeFromSecureStorage(completion: @escaping (Result<Bool, Error>) -> Void)

    Parameters

    completion

    The callback to invoke upon the removal completion.

  • Returns values which are used to perform logout.

    Declaration

    Swift

    private func getLogoutComponents() -> (logoutUrl: URL, authEndpoint: URL, tokenEndpoint: URL, idToken: String)?

    Return Value

    logout url, authorization endpoint url, token endpoint url, id token.

  • Handles authorization result.

    Declaration

    Swift

    private func handleResult(_ result: Result<AnyObject, Error>, with completion: @escaping (Result<AnyObject, Error>) -> Void)

    Parameters

    result

    Result to be handled.

    completion

    The callback to invoke after the result handling.

  • Handles token obtaining result.

    Declaration

    Swift

    private func handleTokenObtainResult(tokenResponse: OIDTokenResponse?, error: Error?, completion: @escaping (Result<AnyObject, Error>) -> Void)

    Parameters

    tokenResponse

    Response to be handled.

    error

    Error which has been occurred during token request.

    completion

    The callback to invoke after the response handling.