@@ -39,21 +39,29 @@ extension ASAuthorizationAppleIDCredential {
3939
4040// MARK: - Authenticate With Apple Dialog
4141
42- private func authenticateWithApple( ) async throws -> ( ASAuthorizationAppleIDCredential , String ) {
43- return try await AuthenticateWithAppleDialog ( ) . authenticate ( )
42+ private func authenticateWithApple(
43+ scopes: [ ASAuthorization . Scope ]
44+ ) async throws -> ( ASAuthorizationAppleIDCredential , String ) {
45+ return try await AuthenticateWithAppleDialog ( scopes: scopes) . authenticate ( )
4446}
4547
4648private class AuthenticateWithAppleDialog : NSObject {
4749 private var continuation : CheckedContinuation < ( ASAuthorizationAppleIDCredential , String ) , Error > ?
4850 private var currentNonce : String ?
51+ private let scopes : [ ASAuthorization . Scope ]
52+
53+ init ( scopes: [ ASAuthorization . Scope ] ) {
54+ self . scopes = scopes
55+ super. init ( )
56+ }
4957
5058 func authenticate( ) async throws -> ( ASAuthorizationAppleIDCredential , String ) {
5159 return try await withCheckedThrowingContinuation { continuation in
5260 self . continuation = continuation
5361
5462 let appleIDProvider = ASAuthorizationAppleIDProvider ( )
5563 let request = appleIDProvider. createRequest ( )
56- request. requestedScopes = [ . fullName , . email ]
64+ request. requestedScopes = scopes
5765
5866 do {
5967 let nonce = try CryptoUtils . randomNonceString ( )
@@ -110,15 +118,15 @@ extension AuthenticateWithAppleDialog: ASAuthorizationControllerDelegate {
110118// MARK: - Apple Provider Swift
111119
112120public class AppleProviderSwift : AuthProviderSwift , DeleteUserSwift {
113- public let scopes : [ String ]
121+ public let scopes : [ ASAuthorization . Scope ]
114122 let providerId = " apple.com "
115123
116- public init ( scopes: [ String ] = [ ] ) {
124+ public init ( scopes: [ ASAuthorization . Scope ] = [ . fullName , . email ] ) {
117125 self . scopes = scopes
118126 }
119127
120128 @MainActor public func createAuthCredential( ) async throws -> AuthCredential {
121- let ( appleIDCredential, nonce) = try await authenticateWithApple ( )
129+ let ( appleIDCredential, nonce) = try await authenticateWithApple ( scopes : scopes )
122130
123131 guard let idTokenString = appleIDCredential. idTokenString else {
124132 throw AuthServiceError . invalidCredentials ( " Unable to fetch identity token from Apple " )
0 commit comments