Skip to content

Commit cc7491f

Browse files
authored
Add SPM sample project for App Check (#339)
1 parent 847af57 commit cc7491f

File tree

13 files changed

+972
-63
lines changed

13 files changed

+972
-63
lines changed

.github/workflows/integration_tests.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,35 @@ jobs:
4040
-destination 'platform=iOS Simulator,name=iPhone 11' \
4141
EMAIL_SECRET=$EMAIL_SECRET \
4242
PASSWORD_SECRET=$PASSWORD_SECRET
43+
44+
app-check-api-token-tests:
45+
runs-on: macOS-12
46+
# Don't run if triggered by a PR from a fork since our Secrets won't be provided to the runner.
47+
if: "!github.event.pull_request.head.repo.fork"
48+
defaults:
49+
run:
50+
working-directory: Samples/Swift/AppAttestExample
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@v3
54+
- name: Build test target for App Check Example
55+
run: |
56+
xcodebuild \
57+
-project AppAttestExample.xcodeproj \
58+
build-for-testing \
59+
-scheme AppAttestExample \
60+
-sdk iphonesimulator \
61+
-destination 'platform=iOS Simulator,name=iPhone 11'
62+
- name: Run test target for App Check Example
63+
env:
64+
AppCheckDebugToken : ${{ secrets.APP_CHECK_DEBUG_TOKEN }}
65+
APP_CHECK_WEB_API_KEY : ${{ secrets.APP_CHECK_WEB_API_KEY }}
66+
run: |
67+
xcodebuild \
68+
-project AppAttestExample.xcodeproj \
69+
test-without-building \
70+
-scheme AppAttestExample \
71+
-sdk iphonesimulator \
72+
-destination 'platform=iOS Simulator,name=iPhone 11' \
73+
AppCheckDebugToken=$AppCheckDebugToken \
74+
APP_CHECK_WEB_API_KEY=$APP_CHECK_WEB_API_KEY

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ Podfile.lock
1919

2020
# Firebase App Check Example
2121
**/GoogleService-Info.plist
22-
**/AppCheckSecrets.xcconfig

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let package = Package(
4848
.package(
4949
name: "AppCheck",
5050
url: "https://github.com/google/app-check.git",
51-
.branch("CocoaPods-0.1.0-alpha.6")),
51+
.branch("CocoaPods-0.1.0-alpha.9")),
5252
.package(
5353
name: "GTMAppAuth",
5454
url: "https://github.com/google/GTMAppAuth.git",

Samples/Swift/AppAttestExample/AppAttestExample.xcodeproj/project.pbxproj

Lines changed: 168 additions & 55 deletions
Large diffs are not rendered by default.

Samples/Swift/AppAttestExample/AppAttestExample.xcodeproj/xcshareddata/xcschemes/AppAttestExample.xcscheme

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,26 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
shouldUseLaunchSchemeArgsEnv = "YES"
30-
shouldAutocreateTestPlan = "YES">
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<TestPlans>
31+
<TestPlanReference
32+
reference = "container:AppAttestExample.xctestplan"
33+
default = "YES">
34+
</TestPlanReference>
35+
</TestPlans>
36+
<Testables>
37+
<TestableReference
38+
skipped = "NO"
39+
parallelizable = "YES">
40+
<BuildableReference
41+
BuildableIdentifier = "primary"
42+
BlueprintIdentifier = "73080B272AAF9BDE00DEF667"
43+
BuildableName = "AppAttestExampleTests.xctest"
44+
BlueprintName = "AppAttestExampleTests"
45+
ReferencedContainer = "container:AppAttestExample.xcodeproj">
46+
</BuildableReference>
47+
</TestableReference>
48+
</Testables>
3149
</TestAction>
3250
<LaunchAction
3351
buildConfiguration = "Debug"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "BE893D88-5ECF-4AF1-95E1-CE186B02A525",
5+
"name" : "Test Scheme Action",
6+
"options" : {
7+
8+
}
9+
}
10+
],
11+
"defaultOptions" : {
12+
"codeCoverage" : false,
13+
"environmentVariableEntries" : [
14+
{
15+
"key" : "AppCheckDebugToken",
16+
"value" : "$(AppCheckDebugToken)"
17+
},
18+
{
19+
"key" : "APP_CHECK_WEB_API_KEY",
20+
"value" : "$(APP_CHECK_WEB_API_KEY)"
21+
}
22+
],
23+
"targetForVariableExpansion" : {
24+
"containerPath" : "container:AppAttestExample.xcodeproj",
25+
"identifier" : "73080B272AAF9BDE00DEF667",
26+
"name" : "AppAttestExampleTests"
27+
}
28+
},
29+
"testTargets" : [
30+
{
31+
"parallelizable" : true,
32+
"target" : {
33+
"containerPath" : "container:AppAttestExample.xcodeproj",
34+
"identifier" : "73080B272AAF9BDE00DEF667",
35+
"name" : "AppAttestExampleTests"
36+
}
37+
}
38+
],
39+
"version" : 1
40+
}

Samples/Swift/AppAttestExample/AppAttestExample/AppCheckSecretReader.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,21 @@ import Foundation
1818

1919
struct AppCheckSecretReader {
2020
private let APIKeyName = "APP_CHECK_WEB_API_KEY"
21+
private let APIKeyResourceName = "AppCheckSecrets"
22+
private let APIKeyExtensionName = "json"
23+
private let debugTokenName = "AppCheckDebugToken"
2124

25+
/// Method to read the App Check debug token from the environment
26+
var debugToken: String? {
27+
guard let debugToken = ProcessInfo.processInfo.environment[debugTokenName],
28+
!debugToken.isEmpty else {
29+
print("Failed to get \(debugTokenName) from environment.")
30+
return nil
31+
}
32+
return debugToken
33+
}
34+
35+
/// Method to read the App Check API key from either the bundle or the environment
2236
var APIKey: String? {
2337
return APIKeyFromBundle ?? APIKeyFromEnvironment
2438
}
@@ -34,9 +48,9 @@ struct AppCheckSecretReader {
3448

3549
/// Method for retrieving API key from the bundle during simulator or debug builds
3650
private var APIKeyFromBundle: String? {
37-
guard let APIKey = Bundle.main.infoDictionary?[APIKeyName] as? String,
51+
guard let APIKey = Bundle.main.object(forInfoDictionaryKey: APIKeyName) as? String,
3852
!APIKey.isEmpty else {
39-
print("Failed to get \(APIKeyName) from Bundle.")
53+
print("Failed to get \(APIKeyName) from environment.")
4054
return nil
4155
}
4256
return APIKey
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Copyright 2023 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+
APP_CHECK_WEB_API_KEY=

0 commit comments

Comments
 (0)