Skip to content

Commit

Permalink
Merge pull request #4 from eventfarm/release/1.3
Browse files Browse the repository at this point in the history
add API method to send the passwordless email
  • Loading branch information
kboskin authored Jan 23, 2024
2 parents a5701a6 + 9dd7c92 commit 37695ae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Sources/AppAuthKit/Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import Foundation
public protocol Authentication {

// MARK: - Methods
func startPasswordless(email: String) -> FusionRequest<Void, AuthenticationError>
func startPasswordless(email: String) -> FusionRequest<OtpCode, AuthenticationError>

func sendPasswordless(code: String) -> FusionRequest<Void, AuthenticationError>

func login(otp: String) -> FusionRequest<OtpCredentials, AuthenticationError>

Expand Down
5 changes: 5 additions & 0 deletions Sources/AppAuthKit/Domain/OtpCode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

public final class OtpCode: Codable {
public let code: String
}
16 changes: 15 additions & 1 deletion Sources/AppAuthKit/FusionAuthAuthentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,26 @@ public struct FusionAuthAuthentication: Authentication {
self.session = session
}

public func startPasswordless(email: String) -> FusionRequest<Void, AuthenticationError> {
public func startPasswordless(email: String) -> FusionRequest<OtpCode, AuthenticationError> {
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<Void, AuthenticationError> {
let url = URL(string: "/api/passwordless/send", relativeTo: self.url)!
let payload: [String: Any] = [
"code": code
]
return FusionRequest(session: session,
url: url,
method: "POST",
Expand Down

0 comments on commit 37695ae

Please sign in to comment.