Receiving Authorization Request Responses on iOS

In order to receive the responses from a ZenKey request, implement ZenKeyAuthorizeButtonDelegate and assign delegate on the button (as shown in Add the ZenKey button on iOS).

extension LoginViewController: ZenKeyAuthorizeButtonDelegate {

    func buttonWillBeginAuthorizing(_ button: ZenKeyAuthorizeButton) {
        // Perform any UI updates like showing an activity indicator.

    func buttonDidFinish(
        _ button: ZenKeyAuthorizeButton,
        withResult result: AuthorizationResult) {

        // Handle the outcome of the request:
        switch result {
        case .code(let authorizedResponse):
            let code = authorizedResponse.code
            let mccmnc = authorizedResponse.mccmnc
            let redirectURI = authorizedResponse.redirectURI
            let codeVerifier = authorizedResponse.codeVerifier
            let nonce = authorizedResponse.nonce
            let correlationId = authorizedResponse.correlationId // string
            let context = authorizedResponse.context // string
            // Pass these identifiers to your secure server to perform a token request.
        case .error(let authorizationError):
            // There was an error with the authorization request
        case .cancelled:
            // The user cancelled their request in the ZenKey application.

Did this page help you?