From 9dd7c92603bde2e9ca80213711603f6a53981eb7 Mon Sep 17 00:00:00 2001 From: Vladyslav Ternovskyi Date: Tue, 23 Jan 2024 12:45:28 +0200 Subject: [PATCH] add API method to send the passwordless email --- Sources/AppAuthKit/Authentication.swift | 4 +++- Sources/AppAuthKit/Domain/OtpCode.swift | 5 +++++ .../AppAuthKit/FusionAuthAuthentication.swift | 16 +++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 Sources/AppAuthKit/Domain/OtpCode.swift diff --git a/Sources/AppAuthKit/Authentication.swift b/Sources/AppAuthKit/Authentication.swift index e3a1a58..3ceb66c 100644 --- a/Sources/AppAuthKit/Authentication.swift +++ b/Sources/AppAuthKit/Authentication.swift @@ -10,7 +10,9 @@ import Foundation public protocol Authentication { // MARK: - Methods - func startPasswordless(email: String) -> FusionRequest + func startPasswordless(email: String) -> FusionRequest + + func sendPasswordless(code: String) -> FusionRequest func login(otp: String) -> FusionRequest diff --git a/Sources/AppAuthKit/Domain/OtpCode.swift b/Sources/AppAuthKit/Domain/OtpCode.swift new file mode 100644 index 0000000..2d629bc --- /dev/null +++ b/Sources/AppAuthKit/Domain/OtpCode.swift @@ -0,0 +1,5 @@ +import Foundation + +public final class OtpCode: Codable { + public let code: String +} diff --git a/Sources/AppAuthKit/FusionAuthAuthentication.swift b/Sources/AppAuthKit/FusionAuthAuthentication.swift index f78c6d9..5b62a24 100644 --- a/Sources/AppAuthKit/FusionAuthAuthentication.swift +++ b/Sources/AppAuthKit/FusionAuthAuthentication.swift @@ -39,12 +39,26 @@ public struct FusionAuthAuthentication: Authentication { self.session = session } - public func startPasswordless(email: String) -> FusionRequest { + public func startPasswordless(email: String) -> FusionRequest { let url = URL(string: "/api/passwordless/start", relativeTo: self.url)! let payload: [String: Any] = [ "applicationId": clientId, "loginId": email ] + return FusionRequest(session: session, + url: url, + method: "POST", + handle: codable, + parameters: payload, + contentType: .json) + .headers(["Authorization": apiKey]) + } + + public func sendPasswordless(code: String) -> FusionRequest { + let url = URL(string: "/api/passwordless/send", relativeTo: self.url)! + let payload: [String: Any] = [ + "code": code + ] return FusionRequest(session: session, url: url, method: "POST",