Skip to content

Commit a1cb565

Browse files
committed
Auth and Messaging Interop for Swift (firebase#9314)
1 parent 6005576 commit a1cb565

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+329
-248
lines changed

.github/workflows/auth.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
pull_request:
55
paths:
66
- 'FirebaseAuth**'
7-
- 'Interop/Auth/Public/*.h'
7+
- 'FirebaseAuth/Interop/*.h'
88
- '.github/workflows/auth.yml'
99
- 'Gemfile*'
1010
schedule:

.github/workflows/database.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- 'Firebase/Database/**'
88
- 'FirebaseSharedSwift**'
99
- 'Example/Database/**'
10-
- 'Interop/Auth/Public/*.h'
10+
- 'FirebaseAuth/Interop/*.h'
1111
- '.github/workflows/database.yml'
1212
- 'Gemfile*'
1313
- 'scripts/run_database_emulator.sh'

.github/workflows/firestore.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
- 'Firestore/**'
2222

2323
# Interop headers
24-
- 'Interop/Auth/Public/*.h'
24+
- 'FirebaseAuth/Interop/*.h'
2525

2626
# FirebaseCore header change
2727
- 'FirebaseCore/Internal'

.github/workflows/functions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ on:
66
- 'FirebaseFunctions**'
77
- 'FirebaseSharedSwift**'
88
- '.github/workflows/functions.yml'
9-
- 'Interop/Auth/Public/*.h'
10-
- 'FirebaseMessaging/Sources/Interop/*.h'
9+
- 'FirebaseAuth/Interop/*.h'
10+
- 'FirebaseMessaging/Interop/*.h'
1111
- 'FirebaseTestingSupport/Functions/**'
1212
- 'FirebaseCombineSwift/Sources/Functions/**'
1313
- 'scripts/setup_quickstart.sh'

.github/workflows/storage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
pull_request:
55
paths:
66
- 'FirebaseStorage**'
7-
- 'Interop/Auth/Public/*.h'
7+
- 'FirebaseAuth/Interop/*.h'
88
- '.github/workflows/storage.yml'
99
- 'scripts/**'
1010
# Rebuild on Ruby infrastructure changes.

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ if(FIREBASE_IOS_BUILD_TESTS)
261261
enable_testing()
262262
endif()
263263

264-
add_subdirectory(FirebaseAppCheck/Interop/)
264+
add_subdirectory(FirebaseAppCheck/Interop)
265265
add_subdirectory(FirebaseCore)
266266
add_subdirectory(Firestore)
267-
add_subdirectory(Interop/Auth)
267+
add_subdirectory(FirebaseAuth/Interop)
268268
add_subdirectory(Interop/CoreDiagnostics)

FirebaseAppCheckInterop.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ Pod::Spec.new do |s|
2727

2828
s.source_files = 'FirebaseAppCheck/Interop/*.[hm]'
2929
s.public_header_files = 'FirebaseAppCheck/Interop/*.h'
30-
end
30+
end

FirebaseAuth.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ supports email and password accounts, as well as several 3rd party authenticatio
3636
s.source_files = [
3737
source + '**/*.[mh]',
3838
'FirebaseCore/Internal/*.h',
39-
'Interop/Auth/Public/*.h',
39+
'FirebaseAuth/Interop/*.h',
4040
]
4141
s.public_header_files = source + 'Public/FirebaseAuth/*.h'
4242
s.preserve_paths = [
File renamed without changes.

Interop/Auth/Public/FIRAuthInterop.h renamed to FirebaseAuth/Interop/FIRAuthInterop.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ NS_SWIFT_NAME(AuthInterop)
3232
@protocol FIRAuthInterop
3333

3434
/// Retrieves the Firebase authentication token, possibly refreshing it if it has expired.
35-
- (void)getTokenForcingRefresh:(BOOL)forceRefresh withCallback:(FIRTokenCallback)callback;
35+
- (void)getTokenForcingRefresh:(BOOL)forceRefresh
36+
withCallback:(FIRTokenCallback)callback
37+
NS_SWIFT_NAME(getToken(forcingRefresh:completion:));
3638

3739
/// Get the current Auth user's UID. Returns nil if there is no user signed in.
3840
- (nullable NSString *)getUserID;

FirebaseAuth/Interop/dummy.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Swift Package Manager needs at least one source file.

FirebaseAuth/Sources/Auth/FIRAuth_Internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717
#import <Foundation/Foundation.h>
18+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
1819
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuth.h"
1920
#import "FirebaseCore/Internal/FIRLogger.h"
20-
#import "Interop/Auth/Public/FIRAuthInterop.h"
2121

2222
@class FIRAuthRequestConfiguration;
2323
@class FIRAuthURLPresenter;

FirebaseAuth/Tests/Unit/FIRAuthLifeCycleTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#import <XCTest/XCTest.h>
1818

19+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
1920
#import "FirebaseCore/Internal/FirebaseCoreInternal.h"
20-
#import "Interop/Auth/Public/FIRAuthInterop.h"
2121

2222
#import "FirebaseAuth/Sources/Auth/FIRAuth_Internal.h"
2323
#import "FirebaseAuth/Sources/Backend/FIRAuthRequestConfiguration.h"

FirebaseAuth/Tests/Unit/FIRAuthTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#import <XCTest/XCTest.h>
2020

2121
#import <GoogleUtilities/GULAppDelegateSwizzler.h>
22+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
2223
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRActionCodeSettings.h"
2324
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAdditionalUserInfo.h"
2425
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuthSettings.h"
@@ -27,7 +28,6 @@
2728
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRGoogleAuthProvider.h"
2829
#import "FirebaseAuth/Sources/Public/FirebaseAuth/FIROAuthProvider.h"
2930
#import "FirebaseCore/Internal/FirebaseCoreInternal.h"
30-
#import "Interop/Auth/Public/FIRAuthInterop.h"
3131

3232
#import "FirebaseAuth/Sources/Auth/FIRAuthDispatcher.h"
3333
#import "FirebaseAuth/Sources/Auth/FIRAuthGlobalWorkQueue.h"

FirebaseAuthInterop.podspec

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Pod::Spec.new do |s|
2+
s.name = 'FirebaseAuthInterop'
3+
s.version = '8.12.0'
4+
s.summary = 'Interfaces that allow other Firebase SDKs to use Auth functionality.'
5+
6+
s.description = <<-DESC
7+
Not for public use.
8+
A set of protocols that other Firebase SDKs can use to interoperate with FirebaseAuth in a safe
9+
and reliable manner.
10+
DESC
11+
12+
s.homepage = 'https://firebase.google.com'
13+
s.license = { :type => 'Apache', :file => 'LICENSE' }
14+
s.authors = 'Google, Inc.'
15+
16+
# NOTE that these should not be used externally, this is for Firebase pods to depend on each
17+
# other.
18+
s.source = {
19+
:git => 'https://github.com/firebase/firebase-ios-sdk.git',
20+
:tag => 'CocoaPods-' + s.version.to_s
21+
}
22+
s.social_media_url = 'https://twitter.com/Firebase'
23+
s.ios.deployment_target = '10.0'
24+
s.osx.deployment_target = '10.12'
25+
s.tvos.deployment_target = '10.0'
26+
s.watchos.deployment_target = '6.0'
27+
28+
s.source_files = 'FirebaseAuth/Interop/*.[hm]'
29+
s.public_header_files = 'FirebaseAuth/Interop/*.h'
30+
end

FirebaseDatabase.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Simplify your iOS development, grow your user base, and monetize more effectivel
3535
base_dir + '**/*.[mh]',
3636
base_dir + 'third_party/Wrap-leveldb/APLevelDB.mm',
3737
base_dir + 'third_party/SocketRocket/fbase64.c',
38-
'Interop/Auth/Public/*.h',
38+
'FirebaseAuth/Interop/*.h',
3939
'FirebaseAppCheck/Interop/*.h',
4040
'FirebaseCore/Internal/*.h',
4141
]

FirebaseDatabase/Sources/Api/FIRDatabase.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
1920
#import "FirebaseCore/Internal/FirebaseCoreInternal.h"
20-
#import "Interop/Auth/Public/FIRAuthInterop.h"
2121

2222
#import "FirebaseDatabase/Sources/Api/FIRDatabaseComponent.h"
2323
#import "FirebaseDatabase/Sources/Api/Private/FIRDatabaseQuery_Private.h"

FirebaseDatabase/Sources/Api/FIRDatabaseComponent.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#import "FirebaseDatabase/Sources/FIRDatabaseConfig_Private.h"
2222

2323
#import "FirebaseAppCheck/Interop/FIRAppCheckInterop.h"
24+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
2425
#import "FirebaseCore/Internal/FirebaseCoreInternal.h"
25-
#import "Interop/Auth/Public/FIRAuthInterop.h"
2626

2727
NS_ASSUME_NONNULL_BEGIN
2828

FirebaseDatabase/Sources/Login/FIRDatabaseConnectionContextProvider.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#import "FirebaseAppCheck/Interop/FIRAppCheckInterop.h"
2222
#import "FirebaseAppCheck/Interop/FIRAppCheckTokenResultInterop.h"
23-
#import "Interop/Auth/Public/FIRAuthInterop.h"
23+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
2424

2525
#import "FirebaseDatabase/Sources/Api/Private/FIRDatabaseQuery_Private.h"
2626
#import "FirebaseDatabase/Sources/Utilities/FUtilities.h"

FirebaseDatabase/Tests/Helpers/FTestHelpers.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#import "FirebaseDatabase/Tests/Helpers/FTestHelpers.h"
1818

19+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
1920
#import "FirebaseCore/Internal/FirebaseCoreInternal.h"
20-
#import "Interop/Auth/Public/FIRAuthInterop.h"
2121

2222
#import "FirebaseDatabase/Sources/Api/Private/FIRDatabase_Private.h"
2323
#import "FirebaseDatabase/Sources/Constants/FConstants.h"

FirebaseDatabase/Tests/Integration/FIRAuthTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#import <XCTest/XCTest.h>
1818

19+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
1920
#import "FirebaseCore/Internal/FirebaseCoreInternal.h"
20-
#import "Interop/Auth/Public/FIRAuthInterop.h"
2121

2222
#import "FirebaseDatabase/Sources/FIRDatabaseConfig_Private.h"
2323
#import "FirebaseDatabase/Tests/Helpers/FTestBase.h"

FirebaseFirestore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
4949
'Firestore/Protos/nanopb/**/*.cc',
5050
'Firestore/core/include/**/*.{cc,mm}',
5151
'Firestore/core/src/**/*.{cc,mm}',
52-
'Interop/Auth/Public/*.h',
52+
'FirebaseAuth/Interop/*.h',
5353
]
5454

5555
# Internal headers that aren't necessarily globally unique. Most C++ internal

FirebaseFunctions.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ Cloud Functions for Firebase.
2525

2626
s.source_files = [
2727
'FirebaseFunctions/Sources/**/*',
28-
'Interop/Auth/Public/*.h',
28+
'FirebaseAuth/Interop/*.h',
2929
'FirebaseAppCheck/Interop/*.h',
3030
'FirebaseCore/Internal/*.h',
31-
'FirebaseMessaging/Sources/Interop/FIRMessagingInterop.h',
31+
'FirebaseMessaging/Interop/FIRMessagingInterop.h',
3232
]
3333
s.public_header_files = 'FirebaseFunctions/Sources/Public/FirebaseFunctions/*.h'
3434

FirebaseFunctions/Sources/FIRFunctions.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#import "FirebaseFunctions/Sources/Public/FirebaseFunctions/FIRFunctions.h"
1919

2020
#import "FirebaseAppCheck/Interop/FIRAppCheckInterop.h"
21+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
2122
#import "FirebaseFunctions/Sources/FIRFunctionsComponent.h"
22-
#import "FirebaseMessaging/Sources/Interop/FIRMessagingInterop.h"
23-
#import "Interop/Auth/Public/FIRAuthInterop.h"
23+
#import "FirebaseMessaging/Interop/FIRMessagingInterop.h"
2424

2525
#import "FirebaseFunctions/Sources/FIRHTTPSCallable+Internal.h"
2626
#import "FirebaseFunctions/Sources/FUNContext.h"

FirebaseFunctions/Sources/FIRFunctionsComponent.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#import "FirebaseCore/Internal/FirebaseCoreInternal.h"
2222

2323
#import "FirebaseAppCheck/Interop/FIRAppCheckInterop.h"
24-
#import "FirebaseMessaging/Sources/Interop/FIRMessagingInterop.h"
25-
#import "Interop/Auth/Public/FIRAuthInterop.h"
24+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
25+
#import "FirebaseMessaging/Interop/FIRMessagingInterop.h"
2626

2727
@interface FIRFunctionsComponent () <FIRLibrary, FIRFunctionsProvider>
2828

FirebaseFunctions/Sources/FUNContext.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
#import "FirebaseAppCheck/Interop/FIRAppCheckInterop.h"
1919
#import "FirebaseAppCheck/Interop/FIRAppCheckTokenResultInterop.h"
20-
#import "FirebaseMessaging/Sources/Interop/FIRMessagingInterop.h"
21-
#import "Interop/Auth/Public/FIRAuthInterop.h"
20+
#import "FirebaseAuth/Interop/FIRAuthInterop.h"
21+
#import "FirebaseMessaging/Interop/FIRMessagingInterop.h"
2222

2323
NS_ASSUME_NONNULL_BEGIN
2424

FirebaseFunctionsSwift.podspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Swift SDK Extensions for Cloud Functions for Firebase.
3838
s.dependency 'FirebaseCore', '~> 8.12'
3939
s.dependency 'FirebaseCoreInternal', '~> 8.12'
4040
s.dependency 'FirebaseAppCheckInterop', '~> 8.12'
41+
s.dependency 'FirebaseAuthInterop', '~> 8.12'
42+
s.dependency 'FirebaseMessagingInterop', '~> 8.12'
4143
s.dependency 'FirebaseSharedSwift', '~> 8.12'
4244
s.dependency 'GTMSessionFetcher/Core', '~> 1.5'
4345

FirebaseFunctionsSwift/Sources/Functions.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,17 @@
1414

1515
import Foundation
1616
import FirebaseAppCheckInterop
17+
import FirebaseAuthInterop
1718
import FirebaseCore
1819
import FirebaseCoreInternal
20+
import FirebaseMessagingInterop
1921
import FirebaseSharedSwift
2022
#if COCOAPODS
2123
import GTMSessionFetcher
2224
#else
2325
import GTMSessionFetcherCore
2426
#endif
2527

26-
// PLACEHOLDERS
27-
@objc public protocol AuthInterop {
28-
func getToken(forcingRefresh: Bool, callback: (String?, Error?) -> Void)
29-
}
30-
31-
@objc public protocol MessagingInterop {
32-
var fcmToken: String { get }
33-
}
34-
35-
// END PLACEHOLDERS
36-
3728
/// File specific constants.
3829
private enum Constants {
3930
static let appCheckTokenHeader = "X-Firebase-AppCheck"

FirebaseFunctionsSwift/Sources/FunctionsContext.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import Foundation
1616
import FirebaseAppCheckInterop
17+
import FirebaseAuthInterop
18+
import FirebaseMessagingInterop
1719

1820
/// FunctionsContext is a helper class for gathering metadata for a function call.
1921
internal class FunctionsContext: NSObject {
@@ -67,7 +69,10 @@ internal class FunctionsContextProvider: NSObject {
6769
dispatchGroup.enter()
6870

6971
appCheck.getToken(forcingRefresh: false) { tokenResult in
70-
appCheckToken = tokenResult.token
72+
// Send only valid token to functions.
73+
if tokenResult.error == nil {
74+
appCheckToken = tokenResult.token
75+
}
7176
dispatchGroup.leave()
7277
}
7378
}

FirebaseFunctionsSwift/Tests/Integration/IntegrationTests.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import Foundation
1616

1717
@testable import FirebaseFunctionsSwift
18+
import FirebaseAuthInterop
19+
import FirebaseMessagingInterop
1820
import XCTest
1921

2022
/// This file was intitialized as a direct port of `FirebaseFunctionsSwift/Tests/IntegrationTests.swift`
@@ -658,17 +660,21 @@ class IntegrationTests: XCTestCase {
658660
}
659661

660662
private class AuthTokenProvider: AuthInterop {
663+
func getUserID() -> String? {
664+
return "fake user"
665+
}
666+
661667
let token: String
662668

663669
init(token: String) {
664670
self.token = token
665671
}
666672

667-
func getToken(forcingRefresh: Bool, callback: (String?, Error?) -> Void) {
668-
callback(token, nil)
673+
func getToken(forcingRefresh: Bool, completion: (String?, Error?) -> Void) {
674+
completion(token, nil)
669675
}
670676
}
671677

672-
private class MessagingTokenProvider: MessagingInterop {
673-
var fcmToken: String { return "fakeFCMToken" }
678+
private class MessagingTokenProvider: NSObject, MessagingInterop {
679+
var fcmToken: String? { return "fakeFCMToken" }
674680
}

0 commit comments

Comments
 (0)