Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions FirebaseAppCheck/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased
- [changed] The default App Check provider is now automatically selected based
on the environment: the Debug provider is used on simulators, and the
DeviceCheck provider is used on devices.

# 12.14.0
- [added] Added `AppAttestProviderFactory` to simplify App Check setup when
using the App Attest provider. (#16182)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2026 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/Foundation.h>

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckProviderFactory.h"

NS_ASSUME_NONNULL_BEGIN

/// The internal default provider factory that is set at +load time. It returns
/// the Debug provider for simulator builds; otherwise, the DeviceCheck
/// provider.
@interface FIRDefaultProviderFactory : NSObject <FIRAppCheckProviderFactory>

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2026 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 "FirebaseAppCheck/Sources/DefaultProviderFactory/FIRDefaultProviderFactory.h"

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheck.h"
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckDebugProviderFactory.h"
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRDeviceCheckProviderFactory.h"

@implementation FIRDefaultProviderFactory

+ (void)load {
[FIRAppCheck setAppCheckProviderFactory:[[self alloc] init]];
}

- (nullable id<FIRAppCheckProvider>)createProviderWithApp:(nonnull FIRApp *)app {
// TODO(ncooke3): What about for local dev targeting macOS?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any possible improvements to the Mac App user journey? Maybe asserting or returning nil with a log to use a custom provider?

#if TARGET_OS_SIMULATOR
return [[[FIRAppCheckDebugProviderFactory alloc] init] createProviderWithApp:app];
// TODO(ncooke3): Add elif case for future reCAPTCHA provider.
#else
return [[[FIRDeviceCheckProviderFactory alloc] init] createProviderWithApp:app];
#endif
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRDeviceCheckProviderFactory.h"

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheck.h"
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRDeviceCheckProvider.h"

@implementation FIRDeviceCheckProviderFactory

+ (void)load {
[FIRAppCheck setAppCheckProviderFactory:[[self alloc] init]];
}

- (nullable id<FIRAppCheckProvider>)createProviderWithApp:(nonnull FIRApp *)app {
return [[FIRDeviceCheckProvider alloc] initWithApp:app];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2026 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 <XCTest/XCTest.h>

#import "FirebaseAppCheck/Sources/DefaultProviderFactory/FIRDefaultProviderFactory.h"
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckAvailability.h"
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckDebugProvider.h"
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRDeviceCheckProvider.h"

#import "FirebaseCore/Extension/FirebaseCoreInternal.h"

FIR_DEVICE_CHECK_PROVIDER_AVAILABILITY
@interface FIRDefaultProviderFactoryTests : XCTestCase
@end

@implementation FIRDefaultProviderFactoryTests

- (void)testCreateProviderWithApp {
FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@"app_id" GCMSenderID:@"sender_id"];
options.APIKey = @"api_key";
options.projectID = @"project_id";
FIRApp *app = [[FIRApp alloc] initInstanceWithName:@"testInitWithValidApp" options:options];
// The following disables automatic token refresh, which could interfere with tests.
app.dataCollectionDefaultEnabled = NO;

FIRDefaultProviderFactory *factory = [[FIRDefaultProviderFactory alloc] init];

id<FIRAppCheckProvider> provider = [factory createProviderWithApp:app];

XCTAssertNotNil(provider);

#if TARGET_OS_SIMULATOR
XCTAssert([provider isKindOfClass:[FIRAppCheckDebugProvider class]]);
#else
XCTAssert([provider isKindOfClass:[FIRDeviceCheckProvider class]]);
#endif
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2026 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 <XCTest/XCTest.h>

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckAvailability.h"
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRDeviceCheckProvider.h"
#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRDeviceCheckProviderFactory.h"

#import "FirebaseCore/Extension/FirebaseCoreInternal.h"

FIR_DEVICE_CHECK_PROVIDER_AVAILABILITY
@interface FIRDeviceCheckProviderFactoryTests : XCTestCase
@end

@implementation FIRDeviceCheckProviderFactoryTests

- (void)testCreateProviderWithApp {
FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:@"app_id" GCMSenderID:@"sender_id"];
options.APIKey = @"api_key";
options.projectID = @"project_id";
FIRApp *app = [[FIRApp alloc] initInstanceWithName:@"testInitWithValidApp" options:options];
// The following disables automatic token refresh, which could interfere with tests.
app.dataCollectionDefaultEnabled = NO;

FIRDeviceCheckProviderFactory *factory = [[FIRDeviceCheckProviderFactory alloc] init];

FIRDeviceCheckProvider *createdProvider = [factory createProviderWithApp:app];

XCTAssert([createdProvider isKindOfClass:[FIRDeviceCheckProvider class]]);
}

@end
Loading