Skip to content

Commit 3e33f6a

Browse files
authored
Support a new offering from Auth0 #1021 (#1024)
Covers changes needed to support new SDK offering from Auth0 - Credentials init make public - APICredentials init make public - CredentialsManagerError , AuthenticationError message made public
1 parent e3e9ec9 commit 3e33f6a

12 files changed

+51
-48
lines changed

Auth0/APICredentials.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ extension APICredentials: Codable {
8787

8888
}
8989

90-
// MARK: - Internal Initializer
91-
92-
extension APICredentials {
90+
public extension APICredentials {
9391

9492
init(from credentials: Credentials) {
9593
self.accessToken = credentials.accessToken

Auth0/AuthenticationError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public struct AuthenticationError: Auth0APIError, @unchecked Sendable {
142142

143143
// MARK: - Error Messages
144144

145-
extension AuthenticationError {
145+
public extension AuthenticationError {
146146

147147
var message: String {
148148
if let description = self.info[apiErrorDescription] as? String ?? self.info["error_description"] as? String {

Auth0/CredentialsManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ public struct CredentialsManager {
610610
callback: callback)
611611
}
612612

613-
func store(apiCredentials: APICredentials, forAudience audience: String) -> Bool {
613+
public func store(apiCredentials: APICredentials, forAudience audience: String) -> Bool {
614614
guard let data = try? apiCredentials.encode() else {
615615
return false
616616
}

Auth0/CredentialsManagerError.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,10 @@ public struct CredentialsManagerError: Auth0Error, Sendable {
7070
/// increase the **Token Expiration** value in the settings page of your [Auth0 API](https://manage.auth0.com/#/apis/).
7171
/// This error does not include a ``Auth0Error/cause-9wuyi``.
7272
public static let largeMinTTL: CredentialsManagerError = .init(code: .largeMinTTL(minTTL: 0, lifetime: 0))
73-
7473
}
7574

7675
// MARK: - Error Messages
77-
78-
extension CredentialsManagerError {
76+
public extension CredentialsManagerError {
7977

8078
var message: String {
8179
switch self.code {

Auth0/MyAccount/AuthenticationMethods/Auth0MyAccountAuthenticationMethods.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
struct Auth0MyAccountAuthenticationMethods: MyAccountAuthenticationMethods {
3+
struct Auth0MyAccountAuthenticationMethods: MyAccountAuthenticationMethods {
44
let url: URL
55
let session: URLSession
66
let token: String

Auth0/MyAccount/AuthenticationMethods/MyAccountAuthenticationMethods.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/// - ``MyAccount``
55
/// - ``MyAccountError``
66
public protocol MyAccountAuthenticationMethods: MyAccountClient {
7-
7+
88
#if PASSKEYS_PLATFORM
99
/// Requests a challenge for enrolling a new passkey. This is the first part of the enrollment flow.
1010
///
@@ -75,7 +75,7 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
7575
@available(iOS 16.6, macOS 13.5, visionOS 1.0, *)
7676
func passkeyEnrollmentChallenge(userIdentityId: String?,
7777
connection: String?) -> Request<PasskeyEnrollmentChallenge, MyAccountError>
78-
78+
7979
/// Enrolls a new passkey credential. This is the last part of the enrollment flow.
8080
///
8181
/// ## Availability
@@ -184,7 +184,7 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
184184
/// - authSession: The unique session identifier for the enrollment as returned by POST /authentication-methods
185185
/// - Returns: A request that will yield an enrolled recovery code authentication method.
186186
func confirmRecoveryCodeEnrollment(id: String,
187-
authSession: String) -> Request<AuthenticationMethod, MyAccountError>
187+
authSession: String) -> Request<AuthenticationMethod, MyAccountError>
188188

189189
/// Requests a challenge for enrolling a TOTP authentication method. This is the first part of the enrollment flow.
190190
///
@@ -394,8 +394,8 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
394394
/// - otpCode: The one-time password code sent to the email address.
395395
/// - Returns: A request that will yield an enrolled email authentication method.
396396
func confirmEmailEnrollment(id: String,
397-
authSession: String,
398-
otpCode: String) -> Request<AuthenticationMethod, MyAccountError>
397+
authSession: String,
398+
otpCode: String) -> Request<AuthenticationMethod, MyAccountError>
399399

400400
/// Requests a challenge for enrolling a Phone authentication method. This is the first part of the enrollment flow.
401401
///
@@ -471,7 +471,7 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
471471
authSession: String,
472472
otpCode: String) -> Request<AuthenticationMethod, MyAccountError>
473473

474-
/// Retrieve detailed list of authentication methods belonging to the authenticated user.
474+
/// Delete an authentication method associated with an id
475475
///
476476
/// ## Availability
477477
///
@@ -481,29 +481,31 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
481481
///
482482
/// ## Scopes Required
483483
///
484-
/// `read:me:authentication_methods`
484+
/// `delete:me:authentication_methods`
485485
///
486486
/// ## Usage
487487
///
488488
/// ```swift
489489
/// Auth0
490490
/// .myAccount(token: apiCredentials.accessToken)
491491
/// .authenticationMethods
492-
/// .getAuthenticationMethods()
492+
/// .deleteAuthenticationMethod(by: id)
493493
/// .start { result in
494494
/// switch result {
495-
/// case .success(let authenticationMethods):
496-
/// print("List of Authentication methods: \(authenticationMethods)")
495+
/// case .success:
496+
/// print("Authentication method is deleted")
497497
/// case .failure(let error):
498498
/// print("Failed with: \(error)")
499499
/// }
500500
/// }
501501
/// ```
502502
///
503-
/// - Returns: A request that will return list of authentication methods of an authenticated user
504-
func getAuthenticationMethods() -> Request<[AuthenticationMethod], MyAccountError>
503+
/// - Parameters:
504+
/// - id: Id of the authentication method user wishes to delete
505+
/// - Returns: A request that will delete an authentication method associated with an id
506+
func deleteAuthenticationMethod(by id: String) -> Request<Void, MyAccountError>
505507

506-
/// Delete an authentication method associated with an id
508+
/// Fetch details of an authentication method associated with an id
507509
///
508510
/// ## Availability
509511
///
@@ -513,31 +515,31 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
513515
///
514516
/// ## Scopes Required
515517
///
516-
/// `delete:me:authentication_methods`
518+
/// `read:me:authentication_methods`
517519
///
518520
/// ## Usage
519521
///
520522
/// ```swift
521523
/// Auth0
522524
/// .myAccount(token: apiCredentials.accessToken)
523525
/// .authenticationMethods
524-
/// .deleteAuthenticationMethod(by: id)
526+
/// .getAuthenticationMethod(by: id)
525527
/// .start { result in
526528
/// switch result {
527-
/// case .success:
528-
/// print("Authentication method is deleted")
529+
/// case .success(let authenticationMethod):
530+
/// print("Fetched authentication method: \(authenticationMethod)")
529531
/// case .failure(let error):
530532
/// print("Failed with: \(error)")
531533
/// }
532534
/// }
533535
/// ```
534536
///
535537
/// - Parameters:
536-
/// - id: Id of the authentication method user wishes to delete
537-
/// - Returns: A request that will delete an authentication method associated with an id
538-
func deleteAuthenticationMethod(by id: String) -> Request<Void, MyAccountError>
538+
/// - id: Id of the returned authentication method
539+
/// - Returns: A request to fetch authentication method associated with the id.
540+
func getAuthenticationMethod(by id: String) -> Request<AuthenticationMethod, MyAccountError>
539541

540-
/// Fetch details of an authentication method associated with an id
542+
/// Retrieve detailed list of authentication methods belonging to the authenticated user.
541543
///
542544
/// ## Availability
543545
///
@@ -555,21 +557,19 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
555557
/// Auth0
556558
/// .myAccount(token: apiCredentials.accessToken)
557559
/// .authenticationMethods
558-
/// .getAuthenticationMethod(by: id)
560+
/// .getAuthenticationMethods()
559561
/// .start { result in
560562
/// switch result {
561-
/// case .success(let authenticationMethod):
562-
/// print("Fetched authentication method: \(authenticationMethod)")
563+
/// case .success(let authenticationMethods):
564+
/// print("List of Authentication methods: \(authenticationMethods)")
563565
/// case .failure(let error):
564566
/// print("Failed with: \(error)")
565567
/// }
566568
/// }
567569
/// ```
568570
///
569-
/// - Parameters:
570-
/// - id: Id of the returned authentication method
571-
/// - Returns: A request to fetch authentication method associated with the id.
572-
func getAuthenticationMethod(by id: String) -> Request<AuthenticationMethod, MyAccountError>
571+
/// - Returns: A request that will return list of authentication methods of an authenticated user
572+
func getAuthenticationMethods() -> Request<[AuthenticationMethod], MyAccountError>
573573

574574
/// List of factors enabled for the Auth0 tenant and available for enrollment by this user.
575575
///

Auth0/MyAccount/MyAccountError.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ public struct MyAccountError: Auth0APIError, @unchecked Sendable {
55
public struct ValidationError: Sendable, Equatable {
66

77
/// Information about the validation error.
8-
let detail: String
8+
public let detail: String
99

1010
/// The property in the request payload that failed validation.
11-
let pointer: String?
11+
public let pointer: String?
1212

13+
public let source: String?
14+
15+
public let field: String?
1316
}
1417

1518
/// Raw error values.
@@ -62,7 +65,7 @@ public struct MyAccountError: Auth0APIError, @unchecked Sendable {
6265

6366
// MARK: - Error Messages
6467

65-
extension MyAccountError {
68+
public extension MyAccountError {
6669

6770
var message: String {
6871
if self.code == unknownError {
@@ -98,6 +101,8 @@ extension MyAccountError.ValidationError {
98101

99102
self.detail = dict["detail"] as? String ?? ""
100103
self.pointer = pointer.isEmpty ? nil : pointer
104+
self.field = dict["field"] as? String
105+
self.source = dict["source"] as? String
101106
}
102107

103108
}

Auth0/Request.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ public struct Request<T, E: Auth0APIError>: Requestable {
121121
} else {
122122
handle(.failure(error), callback)
123123
}
124+
print(error)
124125
} catch {
126+
print(error)
125127
handle(.failure(E(cause: error)), callback)
126128
}
127129
})

Auth0/Requestable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Foundation
2+
import Combine
23

3-
protocol Requestable {
4+
public protocol Requestable {
45
associatedtype ResultType
56
associatedtype ErrorType: Auth0APIError
6-
77
func start(_ callback: @escaping (Result<ResultType, ErrorType>) -> Void)
88
}

Auth0/WebAuthError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public struct WebAuthError: Auth0Error, Sendable {
7979

8080
// MARK: - Error Messages
8181

82-
extension WebAuthError {
82+
public extension WebAuthError {
8383

8484
var message: String {
8585
switch self.code {

0 commit comments

Comments
 (0)