Skip to content

Commit a403ca3

Browse files
authored
[Auth] Add custom provider support for AuthProviderID (#13433)
1 parent 8ac886d commit a403ca3

File tree

4 files changed

+85
-26
lines changed

4 files changed

+85
-26
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 11.1.0
2+
- [added] Added custom provider support to `AuthProviderID`. Note that this change will be breaking
3+
to any code that implemented an exhaustive `switch` on `AuthProviderID` in 11.0.0 - the `switch`
4+
will need expansion. (#13429)
5+
16
# 11.0.0
27
- [fixed] Fixed auth domain matching code to prioritize matching `firebaseapp.com` over `web.app`
38
even if the server returns the `web.app` domain listed first. (#7992)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
/// Enumeration of the available Auth Provider IDs.
18+
public struct AuthProviderID: Equatable {
19+
public let rawValue: String
20+
private init(rawValue: String) {
21+
self.rawValue = rawValue
22+
}
23+
}
24+
25+
public extension AuthProviderID {
26+
static var apple: Self {
27+
Self(rawValue: "apple.com")
28+
}
29+
30+
static var email: Self {
31+
Self(rawValue: "password")
32+
}
33+
34+
static var facebook: Self {
35+
Self(rawValue: "facebook.com")
36+
}
37+
38+
static var gameCenter: Self {
39+
Self(rawValue: "gc.apple.com")
40+
}
41+
42+
static var gitHub: Self {
43+
Self(rawValue: "github.com")
44+
}
45+
46+
static var google: Self {
47+
Self(rawValue: "google.com")
48+
}
49+
50+
static var phone: Self {
51+
Self(rawValue: "phone")
52+
}
53+
54+
static func custom(_ value: String) -> Self {
55+
Self(rawValue: value)
56+
}
57+
}

FirebaseAuth/Sources/Swift/AuthProvider/AuthProviderStrings.swift

Lines changed: 0 additions & 26 deletions
This file was deleted.

FirebaseAuth/Tests/Unit/SwiftAPI.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,4 +702,27 @@ class AuthAPI_hOnlyTests: XCTestCase {
702702
if let _: Date = metadata.lastSignInDate,
703703
let _: Date = metadata.creationDate {}
704704
}
705+
706+
func regression13429(id: AuthProviderID) -> Int {
707+
switch id {
708+
case .apple:
709+
return 1
710+
case .email:
711+
return 2
712+
case .facebook:
713+
return 3
714+
case .gameCenter:
715+
return 4
716+
case .gitHub:
717+
return 5
718+
case .google:
719+
return 6
720+
case .phone:
721+
return 7
722+
case .custom("myCustom"):
723+
return 8
724+
default:
725+
return 9
726+
}
727+
}
705728
}

0 commit comments

Comments
 (0)