Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
run: xcodebuild -scheme UID2 -destination "generic/platform=tvOS"

- name: Run unit tests
run: xcodebuild test -scheme UID2Tests -sdk iphonesimulator16.2 -destination "OS=16.2,name=iPhone 14"
run: xcodebuild test -scheme UID2 -sdk iphonesimulator16.2 -destination "OS=16.2,name=iPhone 14"

- name: Run unit tests on tvOS
run: xcodebuild test -scheme UID2Tests -sdk appletvsimulator16.1 -destination "OS=16.1,name=Apple TV"
run: xcodebuild test -scheme UID2 -sdk appletvsimulator16.1 -destination "OS=16.1,name=Apple TV"

vulnerability-scan:
name: Vulnerability Scan
Expand Down
7 changes: 5 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ line_length:
ignores_comments: true
ignores_urls: true

nesting:
type_level:
warning: 2

disabled_rules:
- unused_optional_binding
- trailing_whitespace

- function_parameter_count
opt_in_rules:
- sorted_imports

52 changes: 0 additions & 52 deletions .swiftpm/xcode/xcshareddata/xcschemes/UID2Tests.xcscheme

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
BFF0F31A2BC6D7E7002646FE /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = BFF0F3192BC6D7E7002646FE /* README.md */; };
E291757C29919C3900500573 /* AppUID2Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = E291757B29919C3900500573 /* AppUID2Client.swift */; };
E291757F2991B19F00500573 /* UID2ServerCredentials.swift in Sources */ = {isa = PBXBuildFile; fileRef = E291757E2991B19F00500573 /* UID2ServerCredentials.swift */; };
E29175812991B22200500573 /* UID2ServerCredentials.json in Resources */ = {isa = PBXBuildFile; fileRef = E29175802991B22200500573 /* UID2ServerCredentials.json */; };
Expand All @@ -26,6 +27,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
BFF0F3192BC6D7E7002646FE /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
E291757A298C1CB900500573 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
E291757B29919C3900500573 /* AppUID2Client.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppUID2Client.swift; sourceTree = "<group>"; };
E291757E2991B19F00500573 /* UID2ServerCredentials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UID2ServerCredentials.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -103,6 +105,7 @@
E2E19004298833A600FFE8C3 /* Assets.xcassets */,
E2E19006298833A600FFE8C3 /* Preview Content */,
E2E190152988566E00FFE8C3 /* Localizable.strings */,
BFF0F3192BC6D7E7002646FE /* README.md */,
);
path = UID2SDKDevelopmentApp;
sourceTree = "<group>";
Expand Down Expand Up @@ -194,6 +197,7 @@
files = (
E2E19008298833A600FFE8C3 /* Preview Assets.xcassets in Resources */,
E2E190162988566E00FFE8C3 /* Localizable.strings in Resources */,
BFF0F31A2BC6D7E7002646FE /* README.md in Resources */,
E2E19005298833A600FFE8C3 /* Assets.xcassets in Resources */,
E29175812991B22200500573 /* UID2ServerCredentials.json in Resources */,
);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ struct IdentityPackageListView: View {
Section(header: Text(LocalizedStringKey("root.title.identitypackage"))
.font(Font.system(size: 22, weight: .bold))) {
IdentityPackageView(viewModel)
}
Section(header: Text(LocalizedStringKey("root.title.identitypackage.notifications"))
.font(Font.system(size: 22, weight: .bold))) {
IdentityPackageNotificationsView(viewModel)
}
}
}.listStyle(.plain)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,19 @@ struct IdentityPackageNotificationsView: View {
Group {
Text(LocalizedStringKey("root.label.identitypackage.notification.publishedStatus"))
.font(Font.system(size: 18, weight: .bold))
Text(viewModel.identityStatus.debugDescription)
Text(status)
.font(Font.system(size: 16, weight: .regular))
}
}

private var status: String {
if let identityStatus = viewModel.identityStatus {
if case .noIdentity = identityStatus {
return NSLocalizedString("common.nil", comment: "")
}
return identityStatus.debugDescription
}

return NSLocalizedString("common.nil", comment: "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

*/

"common.uid2sdk" = "UID2 SDK";
"common.nil" = "Nil";

"root.title.identitypackage" = "Current Identity Package";
"root.title.identitypackage.notifications" = "Notifications";
"root.navigation.title" = "UID2 SDK Dev App";
"root.title.identitypackage" = "Current Identity";
"root.label.error" = "Error Occurred";
"root.button.reset" = "Reset";
"root.button.refresh" = "Manual Refresh";
Expand All @@ -22,4 +21,4 @@
"root.label.identitypackage.refreshExpires" = "Refresh Expires";
"root.label.identitypackage.refreshResponseKey" = "Refresh Response Key";

"root.label.identitypackage.notification.publishedStatus" = "Published Status";
"root.label.identitypackage.notification.publishedStatus" = "Identity Status";
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# UID2 iOS SDK Development App

## Developer Overrides

You can set a different API Endpoint via `UID2ApiUrl` in `Info.plist`, i.e.

```
plutil -replace UID2ApiUrl -string "https://operator-integ.uidapi.com" Development/UID2SDKDevelopmentApp/UID2SDKDevelopmentApp/Info.plist
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,60 @@ struct RootView: View {
private var viewModel = RootViewModel()

@State
private var emailTextField = ""

private var email = ""

@State
private var phone = ""

@State
private var isClientSide = true

var body: some View {

VStack {
Text(viewModel.titleText)
Text("root.navigation.title")
.font(Font.system(size: 28, weight: .bold))
.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
TextField("Email Address", text: $emailTextField)
.textFieldStyle(.roundedBorder)
.textCase(.lowercase)
.textContentType(.emailAddress)
.padding(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16))
.onSubmit {
viewModel.handleEmailEntry(emailTextField.lowercased())
HStack {
TextField("Email Address", text: $email)
.keyboardType(.emailAddress)
.textInputAutocapitalization(.never)
.textContentType(.emailAddress)
Button("Submit Email", systemImage: "arrow.right.circle.fill") {
viewModel.handleEmailEntry(email, clientSide: isClientSide)
}
.labelStyle(.iconOnly)
}
HStack {
TextField("Phone", text: $phone)
.keyboardType(.phonePad)
.textContentType(.telephoneNumber)
Button("Submit Phone", systemImage: "arrow.right.circle.fill") {
viewModel.handlePhoneEntry(phone, clientSide: isClientSide)
}
.labelStyle(.iconOnly)
}
Toggle(isOn: $isClientSide) {
Label("Client Side", systemImage: isClientSide ? "circle.fill" : "circle.slash")
}
.toggleStyle(.button)
Comment thread
dcaunt marked this conversation as resolved.
.frame(height: 32)
if viewModel.error != nil {
ErrorListView(viewModel)
} else {
IdentityPackageListView(viewModel)
}
HStack(alignment: .center, spacing: 20.0) {
Button(LocalizedStringKey("root.button.reset")) {
viewModel.handleResetButton()
emailTextField = ""
Button("root.button.reset") {
viewModel.reset()
}.padding()
Button(LocalizedStringKey("root.button.refresh")) {
viewModel.handleRefreshButton()
Button("root.button.refresh") {
viewModel.refresh()
}.padding()
}
}
.textFieldStyle(.roundedBorder)
.autocorrectionDisabled()
.imageScale(.large)
.padding()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import UID2
@MainActor
class RootViewModel: ObservableObject {

@Published private(set) var titleText = LocalizedStringKey("common.uid2sdk")
@Published private(set) var uid2Identity: UID2Identity?
@Published private(set) var uid2Identity: UID2Identity? {
didSet {
error = nil
}
}
@Published private(set) var identityStatus: IdentityStatus?
@Published private(set) var error: Error?

Expand All @@ -24,7 +27,7 @@ class RootViewModel: ObservableObject {

init() {
UID2Settings.shared.isLoggingEnabled = true
UID2Settings.shared.environment = .oregon

Task {
await UID2Manager.shared.$identity
.receive(on: DispatchQueue.main)
Expand Down Expand Up @@ -84,30 +87,79 @@ class RootViewModel: ObservableObject {

// MARK: - UX Handling Functions

func handleEmailEntry(_ emailAddress: String) {
func handleEmailEntry(_ email: String, clientSide: Bool) {
Task<Void, Never> {
self.error = nil
if clientSide {
struct InvalidEmailError: Error, LocalizedError {
var errorDescription: String = "Invalid email address"
}
guard let normalizedEmail = IdentityType.NormalizedEmail(string: email) else {
error = InvalidEmailError()
return
}
clientSideGenerate(identity: .email(normalizedEmail))
} else {
generateIdentity(email, requestType: .email)
}
}
}

func handlePhoneEntry(_ phone: String, clientSide: Bool) {
self.error = nil
if clientSide {
struct InvalidPhoneError: Error, LocalizedError {
var errorDescription: String = "Phone number is not normalized"
}
guard let normalizedPhone = IdentityType.NormalizedPhone(normalized: phone) else {
error = InvalidPhoneError()
return
}
clientSideGenerate(identity: .phone(normalizedPhone))
} else {
generateIdentity(phone, requestType: .phone)
}
}

func clientSideGenerate(identity: IdentityType) {
let subscriptionID = "toPh8vgJgt"
// swiftlint:disable:next line_length
let serverPublicKeyString = "UID2-X-I-MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKAbPfOz7u25g1fL6riU7p2eeqhjmpALPeYoyjvZmZ1xM2NM8UeOmDZmCIBnKyRZ97pz5bMCjrs38WM22O7LJuw=="

Task<Void, Never> {
do {
try await UID2Manager.shared.generateIdentity(
identity,
subscriptionID: subscriptionID,
serverPublicKey: serverPublicKeyString,
appName: Bundle.main.bundleIdentifier!
)
} catch {
self.error = error
}
}
}

func generateIdentity(_ identity: String, requestType: AppUID2Client.RequestTypes) {
Task<Void, Never> {
do {
guard let identity = try await apiClient.generateIdentity(requestString: emailAddress, requestType: .email) else {
guard let identity = try await apiClient.generateIdentity(requestString: identity, requestType: requestType) else {
return
}
await UID2Manager.shared.setIdentity(identity)
DispatchQueue.main.async {
self.error = nil
}
} catch {
self.error = error
}
}
}
func handleResetButton() {

func reset() {
Task {
await UID2Manager.shared.resetIdentity()
self.error = nil
}
}

func handleRefreshButton() {
func refresh() {
Task {
await UID2Manager.shared.refreshIdentity()
Comment thread
dcaunt marked this conversation as resolved.
}
Expand Down
Loading