Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Last active July 5, 2020 16:21
Show Gist options
  • Save sturdysturge/37755e0f19563473fd0dda380f5385cd to your computer and use it in GitHub Desktop.
Save sturdysturge/37755e0f19563473fd0dda380f5385cd to your computer and use it in GitHub Desktop.
RevDoc SignInWithAppleButton
import SwiftUI
import AuthenticationServices
struct SignInWithAppleView: View {
@State var output = ""
func output(_ result: Result<ASAuthorization, Error>) {
switch result {
case .success (let authResults):
self.output = "Authorization successful\n\n\(authResults)\n\(authResults.provider)\n\(authResults.credential)"
case .failure (let error):
self.output = "Authorization failed: \(error.localizedDescription)"
}
print(self.output)
}
var body: some View {
VStack {
Text("Tap the button to authenticate.\nYou must be signed into an Apple ID on this device.")
.foregroundColor(.black)
.lineLimit(nil)
SignInWithAppleButton(
.signIn,
onRequest: { request in
request.requestedScopes = [.fullName, .email]
},
onCompletion: { result in
output(result)
})
.frame(maxWidth: 375)
.aspectRatio(7, contentMode: .fit)
Text(output)
.foregroundColor(.black)
}
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.white)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment