diff --git a/FirebaseAuth/CHANGELOG.md b/FirebaseAuth/CHANGELOG.md index 109fbb8c14b..fd799061726 100644 --- a/FirebaseAuth/CHANGELOG.md +++ b/FirebaseAuth/CHANGELOG.md @@ -1,3 +1,8 @@ +# 11.1.0 +- [added] Added custom provider support to `AuthProviderID`. Note that this change will be breaking + to any code that implemented an exhaustive `switch` on `AuthProviderID` in 11.0.0 - the `switch` + will need expansion. (#13429) + # 11.0.0 - [fixed] Fixed auth domain matching code to prioritize matching `firebaseapp.com` over `web.app` even if the server returns the `web.app` domain listed first. (#7992) diff --git a/FirebaseAuth/Sources/Swift/AuthProvider/AuthProviderID.swift b/FirebaseAuth/Sources/Swift/AuthProvider/AuthProviderID.swift new file mode 100644 index 00000000000..06bf24af657 --- /dev/null +++ b/FirebaseAuth/Sources/Swift/AuthProvider/AuthProviderID.swift @@ -0,0 +1,57 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation + +/// Enumeration of the available Auth Provider IDs. +public struct AuthProviderID: Equatable { + public let rawValue: String + private init(rawValue: String) { + self.rawValue = rawValue + } +} + +public extension AuthProviderID { + static var apple: Self { + Self(rawValue: "apple.com") + } + + static var email: Self { + Self(rawValue: "password") + } + + static var facebook: Self { + Self(rawValue: "facebook.com") + } + + static var gameCenter: Self { + Self(rawValue: "gc.apple.com") + } + + static var gitHub: Self { + Self(rawValue: "github.com") + } + + static var google: Self { + Self(rawValue: "google.com") + } + + static var phone: Self { + Self(rawValue: "phone") + } + + static func custom(_ value: String) -> Self { + Self(rawValue: value) + } +} diff --git a/FirebaseAuth/Sources/Swift/AuthProvider/AuthProviderStrings.swift b/FirebaseAuth/Sources/Swift/AuthProvider/AuthProviderStrings.swift deleted file mode 100644 index 2ac74c8be6e..00000000000 --- a/FirebaseAuth/Sources/Swift/AuthProvider/AuthProviderStrings.swift +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import Foundation - -/// Enumeration of the available Auth Provider IDs. -public enum AuthProviderID: String { - case apple = "apple.com" - case email = "password" - case facebook = "facebook.com" - case gameCenter = "gc.apple.com" - case gitHub = "github.com" - case google = "google.com" - case phone -} diff --git a/FirebaseAuth/Tests/Unit/SwiftAPI.swift b/FirebaseAuth/Tests/Unit/SwiftAPI.swift index 4944e5fd30c..cc25c6d2002 100644 --- a/FirebaseAuth/Tests/Unit/SwiftAPI.swift +++ b/FirebaseAuth/Tests/Unit/SwiftAPI.swift @@ -702,4 +702,27 @@ class AuthAPI_hOnlyTests: XCTestCase { if let _: Date = metadata.lastSignInDate, let _: Date = metadata.creationDate {} } + + func regression13429(id: AuthProviderID) -> Int { + switch id { + case .apple: + return 1 + case .email: + return 2 + case .facebook: + return 3 + case .gameCenter: + return 4 + case .gitHub: + return 5 + case .google: + return 6 + case .phone: + return 7 + case .custom("myCustom"): + return 8 + default: + return 9 + } + } }