Performing Manual Authorization Requests

Perform manual authorization requests by configuring an AuthorizationService. Pass the code and associated identifiers to your secure server to complete the token request flow.

import ZenKeySDK

class LoginViewController {

    let authService = AuthorizationService()

    func loginWithZenKey() {
        // In response to some UI, perform an authorization using the AuthorizationService.
        let scopes: [Scope] = [.openid, .email, .name, .phone, .postalCode]
        authService.authorize(
            scopes: scopes,
            fromViewController: self) { result in

            switch result {
            case .code(let authorizedResponse):
                let code = authorizedResponse.code
                let mccmnc = authorizedResponse.mccmnc
                let redirectURI = authorizedResponse.redirectURI
                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:
                // Error is returned identity provider
            case .cancelled:
                // The user cancelled request in ZenKey application.
            }
        }
    }
}
```swift import ZenKeySDK

class LoginViewController {

let authService = AuthorizationService()

func loginWithZenKey() {
    // In response to some UI, perform an authorization using the AuthorizationService.
    let scopes: [Scope] = [.openid, .email, .name, .phone, .postalCode]
    authService.authorize(
        scopes: scopes,
        fromViewController: self) { result in

        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:
            // Error is returned identity provider
        case .cancelled:
            // The user cancelled request in ZenKey application.
        }
    }
}

}

</div>


For example, if your app presents its login flow in a WKWebView, you might use the ZenKey button asset from [Integration options on the web](doc:web-integration-options) inside your web content, then a `WKNavigationDelegate` to detect taps on that button before calling the `loginWithZenKey()` function in the above sample code.

 

Did this page help you?