Skip to content

Commit

Permalink
[Auth] Add custom provider support for AuthProviderID (#13433)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 authored Jul 31, 2024
1 parent 8ac886d commit a403ca3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 26 deletions.
5 changes: 5 additions & 0 deletions FirebaseAuth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
57 changes: 57 additions & 0 deletions FirebaseAuth/Sources/Swift/AuthProvider/AuthProviderID.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
26 changes: 0 additions & 26 deletions FirebaseAuth/Sources/Swift/AuthProvider/AuthProviderStrings.swift

This file was deleted.

23 changes: 23 additions & 0 deletions FirebaseAuth/Tests/Unit/SwiftAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit a403ca3

Please sign in to comment.