Receiving Authorization Response in iOS
To receive the authorization parameters and pass them to your secure backend, configure your button delegate to ZenKeyAuthorizeButtonDelegate
and handle buttonDidFinish()
. If the user approves your request, it calls buttonDidFinish()
with a .code
result. The authorizedResponse
includes the authorization code
, mcc
, mnc
, redirectURI
, and codeVerifier
for you to send to your secure backend. You must also handle any .error
or .cancelled
result and inform the user that authorization was unsuccessful.
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 nonce = authorizedResponse.nonce
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
}
}
}
Updated about 1 year ago
Did this page help you?