Skip to content
4 changes: 1 addition & 3 deletions Auth0/APICredentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ extension APICredentials: Codable {

}

// MARK: - Internal Initializer

extension APICredentials {
public extension APICredentials {

init(from credentials: Credentials) {
self.accessToken = credentials.accessToken
Expand Down
2 changes: 1 addition & 1 deletion Auth0/AuthenticationError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public struct AuthenticationError: Auth0APIError, @unchecked Sendable {

// MARK: - Error Messages

extension AuthenticationError {
public extension AuthenticationError {

var message: String {
if let description = self.info[apiErrorDescription] as? String ?? self.info["error_description"] as? String {
Expand Down
2 changes: 1 addition & 1 deletion Auth0/CredentialsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public struct CredentialsManager {
callback: callback)
}

func store(apiCredentials: APICredentials, forAudience audience: String) -> Bool {
public func store(apiCredentials: APICredentials, forAudience audience: String) -> Bool {
guard let data = try? apiCredentials.encode() else {
return false
}
Expand Down
4 changes: 1 addition & 3 deletions Auth0/CredentialsManagerError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ public struct CredentialsManagerError: Auth0Error, Sendable {
/// increase the **Token Expiration** value in the settings page of your [Auth0 API](https://manage.auth0.com/#/apis/).
/// This error does not include a ``Auth0Error/cause-9wuyi``.
public static let largeMinTTL: CredentialsManagerError = .init(code: .largeMinTTL(minTTL: 0, lifetime: 0))

}

// MARK: - Error Messages

extension CredentialsManagerError {
public extension CredentialsManagerError {

var message: String {
switch self.code {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

struct Auth0MyAccountAuthenticationMethods: MyAccountAuthenticationMethods {
struct Auth0MyAccountAuthenticationMethods: MyAccountAuthenticationMethods {
let url: URL
let session: URLSession
let token: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// - ``MyAccount``
/// - ``MyAccountError``
public protocol MyAccountAuthenticationMethods: MyAccountClient {

#if PASSKEYS_PLATFORM
/// Requests a challenge for enrolling a new passkey. This is the first part of the enrollment flow.
///
Expand Down Expand Up @@ -75,7 +75,7 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
@available(iOS 16.6, macOS 13.5, visionOS 1.0, *)
func passkeyEnrollmentChallenge(userIdentityId: String?,
connection: String?) -> Request<PasskeyEnrollmentChallenge, MyAccountError>

/// Enrolls a new passkey credential. This is the last part of the enrollment flow.
///
/// ## Availability
Expand Down Expand Up @@ -184,7 +184,7 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
/// - authSession: The unique session identifier for the enrollment as returned by POST /authentication-methods
/// - Returns: A request that will yield an enrolled recovery code authentication method.
func confirmRecoveryCodeEnrollment(id: String,
authSession: String) -> Request<AuthenticationMethod, MyAccountError>
authSession: String) -> Request<AuthenticationMethod, MyAccountError>

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

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

/// Retrieve detailed list of authentication methods belonging to the authenticated user.
/// Delete an authentication method associated with an id
///
/// ## Availability
///
Expand All @@ -481,29 +481,31 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
///
/// ## Scopes Required
///
/// `read:me:authentication_methods`
/// `delete:me:authentication_methods`
///
/// ## Usage
///
/// ```swift
/// Auth0
/// .myAccount(token: apiCredentials.accessToken)
/// .authenticationMethods
/// .getAuthenticationMethods()
/// .deleteAuthenticationMethod(by: id)
/// .start { result in
/// switch result {
/// case .success(let authenticationMethods):
/// print("List of Authentication methods: \(authenticationMethods)")
/// case .success:
/// print("Authentication method is deleted")
/// case .failure(let error):
/// print("Failed with: \(error)")
/// }
/// }
/// ```
///
/// - Returns: A request that will return list of authentication methods of an authenticated user
func getAuthenticationMethods() -> Request<[AuthenticationMethod], MyAccountError>
/// - Parameters:
/// - id: Id of the authentication method user wishes to delete
/// - Returns: A request that will delete an authentication method associated with an id
func deleteAuthenticationMethod(by id: String) -> Request<Void, MyAccountError>

/// Delete an authentication method associated with an id
/// Fetch details of an authentication method associated with an id
///
/// ## Availability
///
Expand All @@ -513,31 +515,31 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
///
/// ## Scopes Required
///
/// `delete:me:authentication_methods`
/// `read:me:authentication_methods`
///
/// ## Usage
///
/// ```swift
/// Auth0
/// .myAccount(token: apiCredentials.accessToken)
/// .authenticationMethods
/// .deleteAuthenticationMethod(by: id)
/// .getAuthenticationMethod(by: id)
/// .start { result in
/// switch result {
/// case .success:
/// print("Authentication method is deleted")
/// case .success(let authenticationMethod):
/// print("Fetched authentication method: \(authenticationMethod)")
/// case .failure(let error):
/// print("Failed with: \(error)")
/// }
/// }
/// ```
///
/// - Parameters:
/// - id: Id of the authentication method user wishes to delete
/// - Returns: A request that will delete an authentication method associated with an id
func deleteAuthenticationMethod(by id: String) -> Request<Void, MyAccountError>
/// - id: Id of the returned authentication method
/// - Returns: A request to fetch authentication method associated with the id.
func getAuthenticationMethod(by id: String) -> Request<AuthenticationMethod, MyAccountError>

/// Fetch details of an authentication method associated with an id
/// Retrieve detailed list of authentication methods belonging to the authenticated user.
///
/// ## Availability
///
Expand All @@ -555,21 +557,19 @@ public protocol MyAccountAuthenticationMethods: MyAccountClient {
/// Auth0
/// .myAccount(token: apiCredentials.accessToken)
/// .authenticationMethods
/// .getAuthenticationMethod(by: id)
/// .getAuthenticationMethods()
/// .start { result in
/// switch result {
/// case .success(let authenticationMethod):
/// print("Fetched authentication method: \(authenticationMethod)")
/// case .success(let authenticationMethods):
/// print("List of Authentication methods: \(authenticationMethods)")
/// case .failure(let error):
/// print("Failed with: \(error)")
/// }
/// }
/// ```
///
/// - Parameters:
/// - id: Id of the returned authentication method
/// - Returns: A request to fetch authentication method associated with the id.
func getAuthenticationMethod(by id: String) -> Request<AuthenticationMethod, MyAccountError>
/// - Returns: A request that will return list of authentication methods of an authenticated user
func getAuthenticationMethods() -> Request<[AuthenticationMethod], MyAccountError>

/// List of factors enabled for the Auth0 tenant and available for enrollment by this user.
///
Expand Down
11 changes: 8 additions & 3 deletions Auth0/MyAccount/MyAccountError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ public struct MyAccountError: Auth0APIError, @unchecked Sendable {
public struct ValidationError: Sendable, Equatable {

/// Information about the validation error.
let detail: String
public let detail: String

/// The property in the request payload that failed validation.
let pointer: String?
public let pointer: String?

public let source: String?

public let field: String?
}

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

// MARK: - Error Messages

extension MyAccountError {
public extension MyAccountError {

var message: String {
if self.code == unknownError {
Expand Down Expand Up @@ -98,6 +101,8 @@ extension MyAccountError.ValidationError {

self.detail = dict["detail"] as? String ?? ""
self.pointer = pointer.isEmpty ? nil : pointer
self.field = dict["field"] as? String
self.source = dict["source"] as? String
}

}
2 changes: 2 additions & 0 deletions Auth0/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public struct Request<T, E: Auth0APIError>: Requestable {
} else {
handle(.failure(error), callback)
}
print(error)
} catch {
print(error)
handle(.failure(E(cause: error)), callback)
}
})
Expand Down
4 changes: 2 additions & 2 deletions Auth0/Requestable.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Foundation
import Combine

protocol Requestable {
public protocol Requestable {
associatedtype ResultType
associatedtype ErrorType: Auth0APIError

func start(_ callback: @escaping (Result<ResultType, ErrorType>) -> Void)
}
2 changes: 1 addition & 1 deletion Auth0/WebAuthError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public struct WebAuthError: Auth0Error, Sendable {

// MARK: - Error Messages

extension WebAuthError {
public extension WebAuthError {

var message: String {
switch self.code {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ class MyAccountAuthenticationMethodsSpec: QuickSpec {
waitUntil(timeout: Timeout) { done in
authMethods.enrollPhone(phoneNumber: PhoneNumber,
preferredAuthenticationMethod: preferredAuthMethod).start { result in
expect(result).to(haveAuthMethodEnrolmentError(type: "https://auth0.com/api-errors/A0E-400-0003", title: "Validation Error", detail: "Invalid request payload input", statusCode: 400, validationErrors: [MyAccountError.ValidationError(detail: "data/preferred_authentication_method must be equal to one of the allowed values", pointer: "/preferred_authentication_method")]))
expect(result).to(haveAuthMethodEnrolmentError(type: "https://auth0.com/api-errors/A0E-400-0003", title: "Validation Error", detail: "Invalid request payload input", statusCode: 400, validationErrors: [MyAccountError.ValidationError(detail: "data/preferred_authentication_method must be equal to one of the allowed values", pointer: "/preferred_authentication_method", source: nil, field: nil)]))
done()
}
}
Expand Down
8 changes: 4 additions & 4 deletions Auth0Tests/MyAccount/MyAccountErrorSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ class MyAccountErrorSpec: QuickSpec {

it("should return the validation errors") {
let expectedValidationErrors: [(json: [String: String], error: MyAccountError.ValidationError)] = [
(json: ["detail": ""], error: .init(detail: "", pointer: nil)),
(json: ["detail": "foo"], error: .init(detail: "foo", pointer: nil)),
(json: ["detail": "foo", "pointer": ""], error: .init(detail: "foo", pointer: nil)),
(json: ["detail": "foo", "pointer": "baz"], error: .init(detail: "foo", pointer: "baz")),
(json: ["detail": ""], error: .init(detail: "", pointer: nil, source: nil, field: nil)),
(json: ["detail": "foo"], error: .init(detail: "foo", pointer: nil, source: nil, field: nil)),
(json: ["detail": "foo", "pointer": ""], error: .init(detail: "foo", pointer: nil, source: nil, field: nil)),
(json: ["detail": "foo", "pointer": "baz"], error: .init(detail: "foo", pointer: "baz", source: nil, field: nil)),
]
let info: [String: Any] = ["validation_errors": expectedValidationErrors.map(\.json)]
let error = MyAccountError(info: info, statusCode: 400)
Expand Down
Loading