Skip to content

Commit 2c8db8b

Browse files
committed
Updates Request to Requestable protocol across all API clients
1 parent 65383c4 commit 2c8db8b

16 files changed

+211
-185
lines changed

App/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct ContentView: View {
2323

2424
Button {
2525
Task {
26+
2627
#if WEB_AUTH_PLATFORM
2728
#if os(macOS)
2829
await viewModel.webLogin(presentationWindow: currentWindow)
@@ -45,7 +46,6 @@ struct ContentView: View {
4546
Button {
4647
Task {
4748
#if WEB_AUTH_PLATFORM
48-
4949
#if os(macOS)
5050
await viewModel.logout(presentationWindow: currentWindow)
5151
#else

App/ContentViewModel.swift

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ final class ContentViewModel: ObservableObject {
99
@Published var isAuthenticated: Bool = false
1010
private let credentialsManager = CredentialsManager(authentication: Auth0.authentication())
1111

12-
#if WEB_AUTH_PLATFORM
12+
#if WEB_AUTH_PLATFORM
1313
func webLogin(presentationWindow window: Auth0WindowRepresentable? = nil) async {
1414
isLoading = true
1515
errorMessage = nil
1616

17-
#if !os(tvOS) && !os(watchOS)
1817
do {
1918

2019
let credentials = try await Auth0
@@ -33,23 +32,17 @@ final class ContentViewModel: ObservableObject {
3332
} catch {
3433
errorMessage = "Unexpected error: \(error.localizedDescription)"
3534
}
36-
#endif
3735

3836
isLoading = false
3937
}
38+
#endif
4039

40+
#if WEB_AUTH_PLATFORM
4141
func logout(presentationWindow window: Auth0WindowRepresentable? = nil) async {
4242
isLoading = true
4343
errorMessage = nil
44-
#if !os(tvOS) && !os(watchOS)
4544
do {
46-
var webAuth = Auth0.webAuth()
47-
48-
if let window = window {
49-
webAuth = webAuth.presentationWindow(window)
50-
}
51-
52-
try await webAuth.clearSession()
45+
try await Auth0.webAuth().clearSession()
5346

5447
let cleared = credentialsManager.clear()
5548
if cleared {
@@ -62,13 +55,11 @@ final class ContentViewModel: ObservableObject {
6255
} catch {
6356
errorMessage = "Unexpected error: \(error.localizedDescription)"
6457
}
65-
#endif
6658

6759
isLoading = false
6860
}
69-
7061
#endif
71-
62+
7263
func checkAuthentication() async {
7364
do {
7465
let credentials = try await credentialsManager.credentials()

Auth0.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3983,6 +3983,7 @@
39833983
PRODUCT_NAME = "$(TARGET_NAME)";
39843984
PROVISIONING_PROFILE = "";
39853985
PROVISIONING_PROFILE_SPECIFIER = "";
3986+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
39863987
SWIFT_VERSION = 5.0;
39873988
};
39883989
name = Debug;
@@ -4007,6 +4008,7 @@
40074008
PRODUCT_BUNDLE_IDENTIFIER = com.auth0.OAuth2;
40084009
PRODUCT_NAME = "$(TARGET_NAME)";
40094010
PROVISIONING_PROFILE_SPECIFIER = "";
4011+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
40104012
SWIFT_VERSION = 5.0;
40114013
};
40124014
name = Release;
@@ -4047,7 +4049,7 @@
40474049
PRODUCT_NAME = "$(TARGET_NAME)";
40484050
SDKROOT = xros;
40494051
SUPPORTED_PLATFORMS = "xros xrsimulator";
4050-
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
4052+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = WEB_AUTH_PLATFORM;
40514053
SWIFT_EMIT_LOC_STRINGS = NO;
40524054
SWIFT_VERSION = 5.0;
40534055
TARGETED_DEVICE_FAMILY = "1,2,7";

Auth0/Auth0Authentication.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ struct Auth0Authentication: Authentication {
2121
self.telemetry = telemetry
2222
}
2323

24-
func login(email: String, code: String, audience: String?, scope: String) -> Request<Credentials, AuthenticationError> {
24+
func login(email: String, code: String, audience: String?, scope: String) -> any Requestable<Credentials, AuthenticationError> {
2525
return login(username: email, otp: code, realm: "email", audience: audience, scope: scope)
2626
}
2727

28-
func login(phoneNumber: String, code: String, audience: String?, scope: String) -> Request<Credentials, AuthenticationError> {
28+
func login(phoneNumber: String, code: String, audience: String?, scope: String) -> any Requestable<Credentials, AuthenticationError> {
2929
return login(username: phoneNumber, otp: code, realm: "sms", audience: audience, scope: scope)
3030
}
3131

32-
func login(usernameOrEmail username: String, password: String, realmOrConnection realm: String, audience: String?, scope: String) -> Request<Credentials, AuthenticationError> {
32+
func login(usernameOrEmail username: String, password: String, realmOrConnection realm: String, audience: String?, scope: String) -> any Requestable<Credentials, AuthenticationError> {
3333
let url = URL(string: "oauth/token", relativeTo: self.url)!
3434

3535
var payload: [String: Any] = [
@@ -52,7 +52,7 @@ struct Auth0Authentication: Authentication {
5252
dpop: self.dpop)
5353
}
5454

55-
func loginDefaultDirectory(withUsername username: String, password: String, audience: String?, scope: String) -> Request<Credentials, AuthenticationError> {
55+
func loginDefaultDirectory(withUsername username: String, password: String, audience: String?, scope: String) -> any Requestable<Credentials, AuthenticationError> {
5656
let url = URL(string: "oauth/token", relativeTo: self.url)!
5757

5858
var payload: [String: Any] = [
@@ -74,7 +74,7 @@ struct Auth0Authentication: Authentication {
7474
dpop: self.dpop)
7575
}
7676

77-
func login(withOTP otp: String, mfaToken: String) -> Request<Credentials, AuthenticationError> {
77+
func login(withOTP otp: String, mfaToken: String) -> any Requestable<Credentials, AuthenticationError> {
7878
let url = URL(string: "oauth/token", relativeTo: self.url)!
7979

8080
let payload: [String: Any] = [
@@ -94,7 +94,7 @@ struct Auth0Authentication: Authentication {
9494
dpop: self.dpop)
9595
}
9696

97-
func login(withOOBCode oobCode: String, mfaToken: String, bindingCode: String?) -> Request<Credentials, AuthenticationError> {
97+
func login(withOOBCode oobCode: String, mfaToken: String, bindingCode: String?) -> any Requestable<Credentials, AuthenticationError> {
9898
let url = URL(string: "oauth/token", relativeTo: self.url)!
9999

100100
var payload: [String: Any] = [
@@ -118,7 +118,7 @@ struct Auth0Authentication: Authentication {
118118
dpop: self.dpop)
119119
}
120120

121-
func login(withRecoveryCode recoveryCode: String, mfaToken: String) -> Request<Credentials, AuthenticationError> {
121+
func login(withRecoveryCode recoveryCode: String, mfaToken: String) -> any Requestable<Credentials, AuthenticationError> {
122122
let url = URL(string: "oauth/token", relativeTo: self.url)!
123123

124124
let payload: [String: Any] = [
@@ -138,7 +138,7 @@ struct Auth0Authentication: Authentication {
138138
dpop: self.dpop)
139139
}
140140

141-
func multifactorChallenge(mfaToken: String, types: [String]?, authenticatorId: String?) -> Request<Challenge, AuthenticationError> {
141+
func multifactorChallenge(mfaToken: String, types: [String]?, authenticatorId: String?) -> any Requestable<Challenge, AuthenticationError> {
142142
let url = URL(string: "mfa/challenge", relativeTo: self.url)!
143143
var payload: [String: String] = [
144144
"mfa_token": mfaToken,
@@ -166,7 +166,7 @@ struct Auth0Authentication: Authentication {
166166
fullName: PersonNameComponents?,
167167
profile: [String: Any]?,
168168
audience: String?,
169-
scope: String) -> Request<Credentials, AuthenticationError> {
169+
scope: String) -> any Requestable<Credentials, AuthenticationError> {
170170
var parameters: [String: Any] = [:]
171171
var profile: [String: Any] = profile ?? [:]
172172

@@ -192,7 +192,7 @@ struct Auth0Authentication: Authentication {
192192
func login(facebookSessionAccessToken sessionAccessToken: String,
193193
profile: [String: Any],
194194
audience: String?,
195-
scope: String) -> Request<Credentials, AuthenticationError> {
195+
scope: String) -> any Requestable<Credentials, AuthenticationError> {
196196
var parameters: [String: String] = [:]
197197
if let jsonData = try? JSONSerialization.data(withJSONObject: profile, options: []),
198198
let json = String(data: jsonData, encoding: .utf8) {
@@ -205,7 +205,7 @@ struct Auth0Authentication: Authentication {
205205
parameters: parameters)
206206
}
207207

208-
func signup(email: String, username: String? = nil, password: String, connection: String = "Username-Password-Authentication", userMetadata: [String: Any]? = nil, rootAttributes: [String: Any]? = nil) -> Request<DatabaseUser, AuthenticationError> {
208+
func signup(email: String, username: String? = nil, password: String, connection: String = "Username-Password-Authentication", userMetadata: [String: Any]? = nil, rootAttributes: [String: Any]? = nil) -> any Requestable<DatabaseUser, AuthenticationError> {
209209
var payload: [String: Any] = [
210210
"email": email,
211211
"password": password,
@@ -237,7 +237,7 @@ struct Auth0Authentication: Authentication {
237237
connection: String?,
238238
audience: String?,
239239
scope: String,
240-
organization: String?) -> Request<Credentials, AuthenticationError> {
240+
organization: String?) -> any Requestable<Credentials, AuthenticationError> {
241241
let url = URL(string: "oauth/token", relativeTo: self.url)!
242242
let id = passkey.credentialID.encodeBase64URLSafe()
243243

@@ -278,7 +278,7 @@ struct Auth0Authentication: Authentication {
278278

279279
@available(iOS 16.6, macOS 13.5, visionOS 1.0, *)
280280
func passkeyLoginChallenge(connection: String?,
281-
organization: String?) -> Request<PasskeyLoginChallenge, AuthenticationError> {
281+
organization: String?) -> any Requestable<PasskeyLoginChallenge, AuthenticationError> {
282282
let url = URL(string: "passkey/challenge", relativeTo: self.url)!
283283

284284
var payload: [String: String] = ["client_id": self.clientId]
@@ -300,7 +300,7 @@ struct Auth0Authentication: Authentication {
300300
connection: String?,
301301
audience: String?,
302302
scope: String,
303-
organization: String?) -> Request<Credentials, AuthenticationError> {
303+
organization: String?) -> any Requestable<Credentials, AuthenticationError> {
304304
let url = URL(string: "oauth/token", relativeTo: self.url)!
305305
let id = passkey.credentialID.encodeBase64URLSafe()
306306

@@ -344,7 +344,7 @@ struct Auth0Authentication: Authentication {
344344
username: String?,
345345
name: String?,
346346
connection: String?,
347-
organization: String?) -> Request<PasskeySignupChallenge, AuthenticationError> {
347+
organization: String?) -> any Requestable<PasskeySignupChallenge, AuthenticationError> {
348348
let url = URL(string: "passkey/register", relativeTo: self.url)!
349349

350350
var userProfile: [String: Any] = [:]
@@ -370,7 +370,7 @@ struct Auth0Authentication: Authentication {
370370
}
371371
#endif
372372

373-
func resetPassword(email: String, connection: String) -> Request<Void, AuthenticationError> {
373+
func resetPassword(email: String, connection: String) -> any Requestable<Void, AuthenticationError> {
374374
let payload = [
375375
"email": email,
376376
"connection": connection,
@@ -386,7 +386,7 @@ struct Auth0Authentication: Authentication {
386386
telemetry: self.telemetry)
387387
}
388388

389-
func startPasswordless(email: String, type: PasswordlessType, connection: String) -> Request<Void, AuthenticationError> {
389+
func startPasswordless(email: String, type: PasswordlessType, connection: String) -> any Requestable<Void, AuthenticationError> {
390390
let payload: [String: Any] = [
391391
"email": email,
392392
"connection": connection,
@@ -404,7 +404,7 @@ struct Auth0Authentication: Authentication {
404404
telemetry: self.telemetry)
405405
}
406406

407-
func startPasswordless(phoneNumber: String, type: PasswordlessType, connection: String) -> Request<Void, AuthenticationError> {
407+
func startPasswordless(phoneNumber: String, type: PasswordlessType, connection: String) -> any Requestable<Void, AuthenticationError> {
408408
let payload: [String: Any] = [
409409
"phone_number": phoneNumber,
410410
"connection": connection,
@@ -421,7 +421,7 @@ struct Auth0Authentication: Authentication {
421421
telemetry: self.telemetry)
422422
}
423423

424-
func userInfo(withAccessToken accessToken: String, tokenType: String) -> Request<UserInfo, AuthenticationError> {
424+
func userInfo(withAccessToken accessToken: String, tokenType: String) -> any Requestable<UserInfo, AuthenticationError> {
425425
let userInfo = URL(string: "userinfo", relativeTo: self.url)!
426426
let method = "GET"
427427
let headers = self.baseHeaders(accessToken: accessToken, tokenType: tokenType)
@@ -436,7 +436,7 @@ struct Auth0Authentication: Authentication {
436436
dpop: dpop)
437437
}
438438

439-
func codeExchange(withCode code: String, codeVerifier: String, redirectURI: String) -> Request<Credentials, AuthenticationError> {
439+
func codeExchange(withCode code: String, codeVerifier: String, redirectURI: String) -> any Requestable<Credentials, AuthenticationError> {
440440
return self.token().parameters([
441441
"code": code,
442442
"code_verifier": codeVerifier,
@@ -445,15 +445,15 @@ struct Auth0Authentication: Authentication {
445445
])
446446
}
447447

448-
func ssoExchange(withRefreshToken refreshToken: String) -> Request<SSOCredentials, AuthenticationError> {
448+
func ssoExchange(withRefreshToken refreshToken: String) -> any Requestable<SSOCredentials, AuthenticationError> {
449449
return self.token().parameters([
450450
"refresh_token": refreshToken,
451451
"grant_type": "refresh_token",
452452
"audience": "urn:\(self.url.host!):session_transfer"
453453
])
454454
}
455455

456-
func renew(withRefreshToken refreshToken: String, audience: String? = nil, scope: String? = nil) -> Request<Credentials, AuthenticationError> {
456+
func renew(withRefreshToken refreshToken: String, audience: String? = nil, scope: String? = nil) -> any Requestable<Credentials, AuthenticationError> {
457457
let oauthToken = URL(string: "oauth/token", relativeTo: self.url)!
458458

459459
var payload: [String: Any] = [
@@ -481,7 +481,7 @@ struct Auth0Authentication: Authentication {
481481
dpop: self.dpop)
482482
}
483483

484-
func revoke(refreshToken: String) -> Request<Void, AuthenticationError> {
484+
func revoke(refreshToken: String) -> any Requestable<Void, AuthenticationError> {
485485
let payload: [String: Any] = [
486486
"token": refreshToken,
487487
"client_id": self.clientId
@@ -496,7 +496,7 @@ struct Auth0Authentication: Authentication {
496496
telemetry: self.telemetry)
497497
}
498498

499-
func jwks() -> Request<JWKS, AuthenticationError> {
499+
func jwks() -> any Requestable<JWKS, AuthenticationError> {
500500
let jwks = URL(string: ".well-known/jwks.json", relativeTo: self.url)!
501501
return Request(session: session,
502502
url: jwks,
@@ -511,7 +511,7 @@ struct Auth0Authentication: Authentication {
511511
audience: String?,
512512
scope: String,
513513
organization: String?,
514-
parameters: [String: Any]) -> Request<Credentials, AuthenticationError> {
514+
parameters: [String: Any]) -> any Requestable<Credentials, AuthenticationError> {
515515
return self.tokenExchange(subjectToken: subjectToken,
516516
subjectTokenType: subjectTokenType,
517517
scope: scope,
@@ -526,7 +526,7 @@ struct Auth0Authentication: Authentication {
526526

527527
private extension Auth0Authentication {
528528

529-
func login(username: String, otp: String, realm: String, audience: String?, scope: String) -> Request<Credentials, AuthenticationError> {
529+
func login(username: String, otp: String, realm: String, audience: String?, scope: String) -> any Requestable<Credentials, AuthenticationError> {
530530
let url = URL(string: "oauth/token", relativeTo: self.url)!
531531

532532
var payload: [String: Any] = [
@@ -554,7 +554,7 @@ private extension Auth0Authentication {
554554
scope: String,
555555
audience: String?,
556556
organization: String? = nil,
557-
parameters: [String: Any] = [:]) -> Request<Credentials, AuthenticationError> {
557+
parameters: [String: Any] = [:]) -> any Requestable<Credentials, AuthenticationError> {
558558
var parameters: [String: Any] = parameters
559559
parameters["client_id"] = self.clientId
560560
parameters["grant_type"] = "urn:ietf:params:oauth:grant-type:token-exchange"
@@ -575,7 +575,7 @@ private extension Auth0Authentication {
575575
dpop: dpop)
576576
}
577577

578-
func token<T: Codable>() -> Request<T, AuthenticationError> {
578+
func token<T: Codable>() -> any Requestable<T, AuthenticationError> {
579579
let token = URL(string: "oauth/token", relativeTo: self.url)!
580580
let payload: [String: Any] = ["client_id": self.clientId]
581581

0 commit comments

Comments
 (0)