AuthClient
public class AuthClient : IAuthClient, Equatable
Internal implementation of IAuthClient protocol
-
object that stores information required for authentication.
Declaration
Swift
private var config: Config
-
object that handles storing auth state
Declaration
Swift
private let keychainStorage: ISecureStorage?
-
object that creates basic OAuth 2.0 endpoints URLs
Declaration
Swift
private let urlFactory: IUrlFactory
-
object that manages the id token validation.
Declaration
Swift
private let validationManager: IValidationManager
-
object that manages requests to the AppAuth framework.
Declaration
Swift
private let authServiceProvider: IAuthServiceProvider
-
object that manages current authorization state
Declaration
Swift
private var authStateProvider: IAuthStateProvider
-
represents an in-flight external user-agent session
Declaration
Swift
private var currentAuthorizationFlow: OIDExternalUserAgentSession?
-
represents the information needed to construct a OIDAuthorizationService.
Declaration
Swift
private var configuration: OIDServiceConfiguration?
-
Initialises AuthClient with:
Declaration
Swift
init(config: Config, authState: OIDAuthState?, secureStorage: ISecureStorage?, authServiceProvider: IAuthServiceProvider = AuthServiceProvider(), authStateProvider: IAuthStateProvider = AuthStateProvider())
-
Implementation of the Equatable protocol, to be able to compare [AuthClient] objects.
Declaration
Swift
public static func == (lhs: AuthClient, rhs: AuthClient) -> Bool
Parameters
lhs
first object
rhs
second object
Return Value
Boolean value, true if the objects are equal, false otherwise.
-
Sends an authorization request to perform authorization flow See Strivacity APIs, Authentication APIs, Begin an OIDC Authorization Code Flow See OpenID Connect Core 1.0, Section 3.1
Declaration
Swift
public func authorizeAuthCodeFlow(viewController: UIViewController, completion: @escaping (Result<AnyObject, Error>) -> Void)
Parameters
viewController
The UIViewController to present auth flow request.
completion
The callback to invoke upon request completion.
-
Sends request to obtain an id token from auth code See Strivacity Authentication APIs, Obtain an ID Token from an Authorization Code See OpenID Connect Core 1.0, Section 2 Note: The authorization code must already be obtained from [authorizeAuthCodeFlow] or [authorizeHybridFlow]
Declaration
Swift
public func requestIdToken(completion: @escaping (Result<AnyObject, Error>) -> Void)
Parameters
completion
The callback to invoke upon request completion.
-
Sends request to obtain an access token via client credentials See Strivacity Authentication APIs, Obtain an Access Token via Client Credentials
Declaration
Swift
public func requestAccessToken(viewController: UIViewController, completion: @escaping (Result<AnyObject, Error>) -> Void)
Parameters
completion
The callback to invoke upon request completion.
-
Sends an authorization request to perform hybrid flow See Strivacity APIs, Authentication APIs, Begin an OIDC Hybrid Flow See OpenID Connect Core 1.0, Section 3.3
Declaration
Swift
public func authorizeHybridFlow(viewController: UIViewController, completion: @escaping (Result<AnyObject, Error>) -> Void)
Parameters
viewController
The UIViewController to present hybrid flow request.
completion
The callback to invoke upon request completion.
-
Sends request to perform logout See Strivacity Authentication APIs, Begin an OIDC Initiated Logout See OpenID Connect RP-Initiated Logout 1.0 - draft 01
Declaration
Swift
public func logout(viewController: UIViewController, completion: @escaping (Result<Bool, Error>) -> Void)
Parameters
viewController
The UIViewController to present logout request.
completion
The callback to invoke upon request completion.
-
Handles the redirect of the authorization response url.
Declaration
Swift
public func proceedExternalUserAgentFlow(with url: URL) -> Bool
Parameters
url
authorization response url
Return Value
result of redirection, true on success, false on failure.
-
Gives actual authentication state
Declaration
Swift
public func getAuthState() -> AnyObject?
Return Value
authentication state
-
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.
-
doAuthWithoutCodeExchange(configuration:
redirectUri: clientID: clientSecret: scopes: viewController: 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.