Skip to content

Commit

Permalink
updated Pawskey app to handle automated constants baed on devtunnel e…
Browse files Browse the repository at this point in the history
…ndpoints
  • Loading branch information
dmennis committed May 17, 2024
1 parent 084f7bf commit 0f79e06
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 31 deletions.
4 changes: 2 additions & 2 deletions examples/clients/mobile/iOS/PKBank/Constants.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// Created by Dennis Hills on 12/1/23.
//

BANK_AUTH_DOMAIN = replace-with-your-keycloak-hostname
BANK_API_DOMAIN = replace-with-your-bank-api-hostname
BANK_AUTH_DOMAIN = fun-lake-gjm1dq4-8081.usw2.devtunnels.ms
BANK_API_DOMAIN = fun-lake-gjm1dq4-8082.usw2.devtunnels.ms

10 changes: 10 additions & 0 deletions examples/clients/mobile/iOS/PawsKey/Constants.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Constants.xcconfig
// PawsKey
//
// Created by Yubico Developer Program on 5/17/24.
// Copyright © 2024 Yubico. All rights reserved.
//

API_BASE_URI = replace-with-your-api-hostname
RP_ID = replace-with-your-RPID-domain
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
260C034529C03DC60024BF50 /* RelyingParty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260C034429C03DC60024BF50 /* RelyingParty.swift */; };
265E131229C530B300B40759 /* SignInFailedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 265E131129C530B300B40759 /* SignInFailedViewController.swift */; };
26717EB52BF7DFFE009A99A5 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26717EB42BF7DFFE009A99A5 /* Constants.swift */; };
E09D56EF2669A5F2004A809B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E09D56EE2669A5F2004A809B /* AppDelegate.swift */; };
E09D56F12669A5F2004A809B /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E09D56F02669A5F2004A809B /* SceneDelegate.swift */; };
E09D56F62669A5F2004A809B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E09D56F42669A5F2004A809B /* Main.storyboard */; };
Expand All @@ -23,6 +24,8 @@
260C034329BFEFAC0024BF50 /* PawsKeyDebug.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PawsKeyDebug.entitlements; sourceTree = "<group>"; };
260C034429C03DC60024BF50 /* RelyingParty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelyingParty.swift; sourceTree = "<group>"; };
265E131129C530B300B40759 /* SignInFailedViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInFailedViewController.swift; sourceTree = "<group>"; };
26717EB42BF7DFFE009A99A5 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
26CEE0E92BF7D5E100E5600C /* Constants.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Constants.xcconfig; sourceTree = "<group>"; };
2C088C6DEDBE3305FCC6C1B2 /* Pods_PawsKey.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PawsKey.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D0EE5C66F4ACE15F993A4F03 /* SampleCode.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = SampleCode.xcconfig; path = Configuration/SampleCode.xcconfig; sourceTree = "<group>"; };
E09D56EB2669A5F2004A809B /* PawsKey.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PawsKey.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -59,6 +62,7 @@
E09D56E22669A5F2004A809B = {
isa = PBXGroup;
children = (
26CEE0E92BF7D5E100E5600C /* Constants.xcconfig */,
260C034329BFEFAC0024BF50 /* PawsKeyDebug.entitlements */,
E0C944D92669A8F20033265C /* README.md */,
E09D56ED2669A5F2004A809B /* Shared */,
Expand Down Expand Up @@ -91,6 +95,7 @@
E09D56FC2669A5F5004A809B /* Info.plist */,
260C034429C03DC60024BF50 /* RelyingParty.swift */,
265E131129C530B300B40759 /* SignInFailedViewController.swift */,
26717EB42BF7DFFE009A99A5 /* Constants.swift */,
);
path = Shared;
sourceTree = "<group>";
Expand Down Expand Up @@ -120,8 +125,9 @@
E09D56E32669A5F2004A809B /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1250;
LastUpgradeCheck = 1250;
LastUpgradeCheck = 1540;
ORGANIZATIONNAME = Yubico;
TargetAttributes = {
E09D56EA2669A5F2004A809B = {
Expand Down Expand Up @@ -172,6 +178,7 @@
E0C944D72669A8840033265C /* UserHomeViewController.swift in Sources */,
E09D56F12669A5F2004A809B /* SceneDelegate.swift in Sources */,
260C034529C03DC60024BF50 /* RelyingParty.swift in Sources */,
26717EB52BF7DFFE009A99A5 /* Constants.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -199,7 +206,7 @@
/* Begin XCBuildConfiguration section */
E09D56FD2669A5F5004A809B /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = D0EE5C66F4ACE15F993A4F03 /* SampleCode.xcconfig */;
baseConfigurationReference = 26CEE0E92BF7D5E100E5600C /* Constants.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -235,6 +242,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand All @@ -249,7 +257,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand All @@ -261,7 +269,7 @@
};
E09D56FE2669A5F5004A809B /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = D0EE5C66F4ACE15F993A4F03 /* SampleCode.xcconfig */;
baseConfigurationReference = 26CEE0E92BF7D5E100E5600C /* Constants.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
Expand Down Expand Up @@ -297,6 +305,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -305,7 +314,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -317,25 +326,24 @@
};
E09D57002669A5F5004A809B /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = D0EE5C66F4ACE15F993A4F03 /* SampleCode.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_ENTITLEMENTS = PawsKeyDebug.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1221;
DEVELOPMENT_TEAM = A6586UA84V;
DEVELOPMENT_TEAM = FC263886LH;
INFOPLIST_FILE = Shared/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = PawsKey;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2;
PRODUCT_BUNDLE_IDENTIFIER = fyi.passkey.pawskey;
PRODUCT_BUNDLE_IDENTIFIER = co.pawskey.app;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTS_MACCATALYST = YES;
Expand All @@ -347,25 +355,24 @@
};
E09D57012669A5F5004A809B /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = D0EE5C66F4ACE15F993A4F03 /* SampleCode.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_ENTITLEMENTS = Shared/PawsKey.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1221;
DEVELOPMENT_TEAM = A6586UA84V;
DEVELOPMENT_TEAM = FC263886LH;
INFOPLIST_FILE = Shared/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = PawsKey;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.2;
PRODUCT_BUNDLE_IDENTIFIER = fyi.passkey.pawskey;
PRODUCT_BUNDLE_IDENTIFIER = co.pawskey.app;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SUPPORTS_MACCATALYST = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1540"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>webcredentials:replace-with-your-hostname.trycloudflare.com?mode=developer</string>
<string>webcredentials:pawskey.co?mode=developer</string>
</array>
</dict>
</plist>
13 changes: 6 additions & 7 deletions examples/clients/mobile/iOS/PawsKey/Shared/AccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ extension NSNotification.Name {
}

class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProviding, ASAuthorizationControllerDelegate {
let domain = "replace-with-your-hostname.trycloudflare.com" // This needs to match your RP Id

var authenticationAnchor: ASPresentationAnchor?
var isPerformingModalReqest = false
Expand All @@ -35,7 +34,7 @@ class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProv
self.userName = userName

// Initialize SecurityKey ASAuthorization provider
let securityKeyCredentialProvider = ASAuthorizationSecurityKeyPublicKeyCredentialProvider(relyingPartyIdentifier: domain)
let securityKeyCredentialProvider = ASAuthorizationSecurityKeyPublicKeyCredentialProvider(relyingPartyIdentifier: RPID.domain)

let rp = RelyingParty()

Expand Down Expand Up @@ -97,7 +96,7 @@ class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProv
if(userName.isEmpty){ return }
self.userName = userName

let publicKeyPlatformCredentialProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: domain)
let publicKeyPlatformCredentialProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: RPID.domain)

let rp = RelyingParty()

Expand Down Expand Up @@ -132,7 +131,7 @@ class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProv
self.authenticationAnchor = anchor
self.userName = userName

let publicKeySecurityKeyCredentialProvider = ASAuthorizationSecurityKeyPublicKeyCredentialProvider(relyingPartyIdentifier: domain)
let publicKeySecurityKeyCredentialProvider = ASAuthorizationSecurityKeyPublicKeyCredentialProvider(relyingPartyIdentifier: RPID.domain)

// Fetch the assertion options from the server and then make a passkey assertion request
let rp = RelyingParty()
Expand Down Expand Up @@ -171,7 +170,7 @@ class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProv
self.authenticationAnchor = anchor
self.userName = userName

let publicKeyPlatformCredentialProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: domain)
let publicKeyPlatformCredentialProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: RPID.domain)

// Fetch the assertion options from the server and then make a passkey assertion request
let rp = RelyingParty()
Expand Down Expand Up @@ -202,8 +201,8 @@ class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProv
self.authenticationAnchor = anchor
self.userName = userName

let publicKeyPlatformCredentialProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: domain)
let publicKeySecurityKeyCredentialProvider = ASAuthorizationSecurityKeyPublicKeyCredentialProvider(relyingPartyIdentifier: domain)
let publicKeyPlatformCredentialProvider = ASAuthorizationPlatformPublicKeyCredentialProvider(relyingPartyIdentifier: RPID.domain)
let publicKeySecurityKeyCredentialProvider = ASAuthorizationSecurityKeyPublicKeyCredentialProvider(relyingPartyIdentifier: RPID.domain)

// Fetch the assertion options from the server and then make a passkey assertion request
let rp = RelyingParty()
Expand Down
45 changes: 45 additions & 0 deletions examples/clients/mobile/iOS/PawsKey/Shared/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Constants.swift
// PawsKey
//
// Created by Dennis Hills on 5/17/24.
// Copyright © 2024 Yubico. All rights reserved.
//
// See Configuration/Constants.xcconfig for API_BASE_URI/RP_ID values
//

import Foundation

enum Constants {
enum Error: Swift.Error {
case missingKey, invalidValue
}

static func value<T>(for key: String) throws -> T where T: LosslessStringConvertible {
guard let object = Bundle.main.object(forInfoDictionaryKey:key) else {
throw Error.missingKey
}

switch object {
case let value as T:
return value
case let string as String:
guard let value = T(string) else { fallthrough }
return value
default:
throw Error.invalidValue
}
}
}

enum APIBASEURI {
static var domain: String {
return try! Constants.value(for: "API_BASE_URI")
}
}

enum RPID {
static var domain: String {
return try! Constants.value(for: "RP_ID")
}
}
4 changes: 4 additions & 0 deletions examples/clients/mobile/iOS/PawsKey/Shared/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>API_BASE_URI</key>
<string>https://$(API_BASE_URI)</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand All @@ -22,6 +24,8 @@
<true/>
<key>NSLocalNetworkUsageDescription</key>
<string>To access a relying party running on your local network</string>
<key>RP_ID</key>
<string>$(RP_ID)</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>webcredentials:passkey.fyi?mode=developer</string>
<string>webcredentials:pawskey.co?mode=developer</string>
</array>
</dict>
</plist>
11 changes: 5 additions & 6 deletions examples/clients/mobile/iOS/PawsKey/Shared/RelyingParty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import Foundation

class RelyingParty {

static let API_ENDPOINT = "https://replace-with-your-hostname.trycloudflare.com/v1"

// #ATTESTATION OPTIONS

// Get Attestation Options for user - /v1/attestation/options (POST)
Expand Down Expand Up @@ -163,15 +161,16 @@ class RelyingParty {
}

func getURLEndpoint(endpoint: Endpoint) -> URL? {

switch endpoint {
case .attestationOptions :
return URL(string: RelyingParty.API_ENDPOINT + "/attestation/options")
return URL(string: APIBASEURI.domain + "/v1/attestation/options")
case .attestationResult:
return URL(string: RelyingParty.API_ENDPOINT + "/attestation/result")
return URL(string: APIBASEURI.domain + "/v1/attestation/result")
case .assertionOptions:
return URL(string: RelyingParty.API_ENDPOINT + "/assertion/options")
return URL(string: APIBASEURI.domain + "/v1/assertion/options")
case .assertionResult:
return URL(string: RelyingParty.API_ENDPOINT + "/assertion/result")
return URL(string: APIBASEURI.domain + "/v1/assertion/result")
}
}
}
Expand Down

0 comments on commit 0f79e06

Please sign in to comment.