Skip to content

Instantly share code, notes, and snippets.

@cardoso
Created May 1, 2020 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cardoso/0403c2e01cec6e9c2a4a2b9da70a0020 to your computer and use it in GitHub Desktop.
Save cardoso/0403c2e01cec6e9c2a4a2b9da70a0020 to your computer and use it in GitHub Desktop.
extension AuthViewController: ASAuthorizationControllerDelegate {
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
let cred = authorization.credential as! ASAuthorizationAppleIDCredential
let code = String(data: cred.authorizationCode!, encoding: .utf8)!
var name: String? = nil
if let fullName = cred.fullName {
name = PersonNameComponentsFormatter().string(from: fullName)
}
let request = AuthRequest(appleUid: cred.user, appleAuthCode: code, name: name)
authenticate(request: request) { [weak self] res, error in
DispatchQueue.main.async {
guard let res = res else {
let alert = UIAlertController(title: "Error", message: error, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default))
self?.present(alert, animated: true)
return
}
Client.config = .init(apiKey: res.apiKey, logOptions: .info)
let extraData = UserExtraData(name: res.name)
let user = User(id: res.streamId, extraData: extraData)
Client.shared.set(user: user, token: res.streamToken)
self?.performSegue(withIdentifier: "kAuthToContactsSegueId", sender: nil)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment