How to implement Sign in with Apple in SwiftUI?
Sign in with Apple in SwiftUI
Add a Comment
Code Block Swift SignInWithAppleButton(.signIn) { request in request.reqestedScopes = [.fullName, .email] } onCompletion: { result in switch result { case .success(let authResults): print("Authorisation successful") case .error(let error): print("Authorisation failed: \(error.localizedDescription)") } } // black button .signInWithAppleButtonStyle(.black) // white button .signInWithAppleButtonStyle(.white) // white with border .signInWithAppleButtonStyle(.whiteOutline)
Nice one
Great answer - may I just point out a few additional details needed for this to work:
import AuthenticationServicesrequest.requestedScopes = [.fullName, .email] (typo : you missed the 'u')case .failure instead of case.errorPlease update your answer if you can.
Code Block Swift SignInWithAppleButton(.signIn) { request in request.reqestedScopes = [.fullName, .email] } onCompletion: { result in switch result { case .success(let authResults): print("Authorisation successful") case .error(let error): print("Authorisation failed: \(error.localizedDescription)") } } // black button .signInWithAppleButtonStyle(.black) // white button .signInWithAppleButtonStyle(.white) // white with border .signInWithAppleButtonStyle(.whiteOutline)
Nice one
Great answer - may I just point out a few additional details needed for this to work:
import AuthenticationServicesrequest.requestedScopes = [.fullName, .email] (typo : you missed the 'u')case .failure instead of case.errorPlease update your answer if you can.
This approach is excellent. However, I got identityToken and authorizationCode, but I can't get the full user name or email. Is there some additional reason with this method why I can't get them?
@matejaOpacic Can you please explain how did you get the identityToken and authorization Code ?
Fast forward to 2022
import SwiftUI
import AuthenticationServices
struct AuthView: View {
var body: some View {
SignInWithAppleButton(.continue) { request in
request.requestedScopes = [.fullName, .email]
} onCompletion: { result in
switch result {
case .success(let authResults):
print("Authorisation successful")
case .failure(let error):
print("Authorisation failed: \(error.localizedDescription)")
}
}
// black button
.signInWithAppleButtonStyle(.black)
// white button
.signInWithAppleButtonStyle(.white)
// white with border
.signInWithAppleButtonStyle(.whiteOutline)
}
}
Facing same issue for this solution