Skip to content

Instantly share code, notes, and snippets.

@Yoloabdo
Last active June 5, 2020 14:07
Show Gist options
  • Select an option

  • Save Yoloabdo/6e8fa79ba227dc9c055ab85418d9f735 to your computer and use it in GitHub Desktop.

Select an option

Save Yoloabdo/6e8fa79ba227dc9c055ab85418d9f735 to your computer and use it in GitHub Desktop.
@available(iOS 13.0, *)
extension AppleAuthService: ASAuthorizationControllerDelegate {
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
backendAuth?.authorize(appleIDCredential)
}
}
func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) {
switch error {
case let error as ASAuthorizationError:
delegate?.authService(authType, didFailToAuthorizeWith: AuthenticationError.appleError(code: error.errorCode))
default:
delegate?.authService(authType, didFailToAuthorizeWith: error)
}
}
}
@available(iOS 13.0, *)
extension AppleAuthService: ASAuthorizationControllerPresentationContextProviding {
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
guard let window = viewController?.view.window else {
fatalError("couldn't find window")
}
return window
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment