From f2805273196e2c22c3e9b8bac1a0410a07ad3cbe Mon Sep 17 00:00:00 2001 From: Asaf Shen Date: Mon, 21 Aug 2023 13:48:25 +0300 Subject: [PATCH 1/4] Replace password - return a session --- src/internal/http/DescopeClient.swift | 4 ++-- src/internal/routes/Password.swift | 4 ++-- src/sdk/Routes.swift | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/internal/http/DescopeClient.swift b/src/internal/http/DescopeClient.swift index cfc590f..b1358f8 100644 --- a/src/internal/http/DescopeClient.swift +++ b/src/internal/http/DescopeClient.swift @@ -108,8 +108,8 @@ class DescopeClient: HTTPClient { ]) } - func passwordReplace(loginId: String, oldPassword: String, newPassword: String) async throws { - try await post("auth/password/replace", body: [ + func passwordReplace(loginId: String, oldPassword: String, newPassword: String) async throws -> JWTResponse { + return try await post("auth/password/replace", body: [ "loginId": loginId, "oldPassword": oldPassword, "newPassword": newPassword, diff --git a/src/internal/routes/Password.swift b/src/internal/routes/Password.swift index f0a13c0..931b737 100644 --- a/src/internal/routes/Password.swift +++ b/src/internal/routes/Password.swift @@ -18,8 +18,8 @@ class Password: DescopePassword { try await client.passwordUpdate(loginId: loginId, newPassword: newPassword, refreshJwt: refreshJwt) } - func replace(loginId: String, oldPassword: String, newPassword: String) async throws { - try await client.passwordReplace(loginId: loginId, oldPassword: oldPassword, newPassword: newPassword) + func replace(loginId: String, oldPassword: String, newPassword: String) async throws -> AuthenticationResponse { + try await client.passwordReplace(loginId: loginId, oldPassword: oldPassword, newPassword: newPassword).convert() } func sendReset(loginId: String, redirectURL: String?) async throws { diff --git a/src/sdk/Routes.swift b/src/sdk/Routes.swift index 49eaa9b..d26b571 100644 --- a/src/sdk/Routes.swift +++ b/src/sdk/Routes.swift @@ -518,7 +518,8 @@ public protocol DescopePassword { /// - loginId: The existing user's loginId. /// - oldPassword: The user's current password. /// - newPassword: The new password to set for the user. - func replace(loginId: String, oldPassword: String, newPassword: String) async throws + /// - Returns: An ``AuthenticationResponse`` value upon successful authentication. + func replace(loginId: String, oldPassword: String, newPassword: String) async throws -> AuthenticationResponse /// Sends a password reset email to the user. /// From f1fcee54d86331856d91ba24faa3bba3bd01a559 Mon Sep 17 00:00:00 2001 From: Asaf Shen Date: Mon, 21 Aug 2023 14:09:37 +0300 Subject: [PATCH 2/4] build and readme --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++ src/sdk/Callbacks.swift | 3 ++- src/sdk/Routes.swift | 2 +- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1158a98..0cd7f23 100644 --- a/README.md +++ b/README.md @@ -293,3 +293,49 @@ code the app produces. ```swift let authResponse = try await Descope.totp.verify(loginId: "andy@example.com", code: "987654") ``` + +### Password Authentication + +Authenticate users using a password. + +#### Sign Up with Password + +To create a new user that can later sign in with a password: + +```swift +let authResponse = try await descope.password.signUp(loginId: "andy@example.com", password: "securePassword123!", details: SignUpDetails( + name: "Andy Rhoads" +)) +``` + +#### Sign In with Password + +Authenticate an existing user using a password: + +```swift +let authResponse = try await descope.password.signIn(loginId: "andy@example.com", password: "securePassword123") +``` + +#### Update Password + +If you need to update a user's password: + +```swift +try await descope.password.update(loginId: "andy@example.com", newPassword: "newSecurePassword456", refreshJwt: "yourRefreshJWT") +``` + +#### Replace Password + +To replace a user's password by providing their current password: + +```swift +let authResponse = try await descope.password.replace(loginId: "andy@example.com", oldPassword: "SecurePassword123!", newPassword: "NewSecurePassword456!") +``` + +#### Send Password Reset Email + +Initiate a password reset by sending an email: + +```swift +try await descope.password.sendReset(loginId: "andy@example.com", redirectURL: "exampleauthschema://my-app.com/handle-reset") +``` diff --git a/src/sdk/Callbacks.swift b/src/sdk/Callbacks.swift index dffb30d..4ddb94b 100644 --- a/src/sdk/Callbacks.swift +++ b/src/sdk/Callbacks.swift @@ -675,7 +675,8 @@ public extension DescopePassword { /// - loginId: The existing user's loginId. /// - oldPassword: The user's current password. /// - newPassword: The new password to set for the user. - func replace(loginId: String, oldPassword: String, newPassword: String, completion: @escaping (Result) -> Void) { + /// - Returns: An ``AuthenticationResponse`` value upon successful replacement and authentication. + func replace(loginId: String, oldPassword: String, newPassword: String, completion: @escaping (Result) -> Void) { Task { do { completion(.success(try await replace(loginId: loginId, oldPassword: oldPassword, newPassword: newPassword))) diff --git a/src/sdk/Routes.swift b/src/sdk/Routes.swift index d26b571..d8c3230 100644 --- a/src/sdk/Routes.swift +++ b/src/sdk/Routes.swift @@ -518,7 +518,7 @@ public protocol DescopePassword { /// - loginId: The existing user's loginId. /// - oldPassword: The user's current password. /// - newPassword: The new password to set for the user. - /// - Returns: An ``AuthenticationResponse`` value upon successful authentication. + /// - Returns: An ``AuthenticationResponse`` value upon successful replacement and authentication. func replace(loginId: String, oldPassword: String, newPassword: String) async throws -> AuthenticationResponse /// Sends a password reset email to the user. From 052beee2ad380865f08e1d8231a36d0804b14ef5 Mon Sep 17 00:00:00 2001 From: Asaf Shen Date: Mon, 21 Aug 2023 14:11:36 +0300 Subject: [PATCH 3/4] rename --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0cd7f23..6837f3a 100644 --- a/README.md +++ b/README.md @@ -303,7 +303,7 @@ Authenticate users using a password. To create a new user that can later sign in with a password: ```swift -let authResponse = try await descope.password.signUp(loginId: "andy@example.com", password: "securePassword123!", details: SignUpDetails( +let authResponse = try await Descope.password.signUp(loginId: "andy@example.com", password: "securePassword123!", details: SignUpDetails( name: "Andy Rhoads" )) ``` @@ -313,7 +313,7 @@ let authResponse = try await descope.password.signUp(loginId: "andy@example.com" Authenticate an existing user using a password: ```swift -let authResponse = try await descope.password.signIn(loginId: "andy@example.com", password: "securePassword123") +let authResponse = try await Descope.password.signIn(loginId: "andy@example.com", password: "securePassword123") ``` #### Update Password @@ -321,7 +321,7 @@ let authResponse = try await descope.password.signIn(loginId: "andy@example.com" If you need to update a user's password: ```swift -try await descope.password.update(loginId: "andy@example.com", newPassword: "newSecurePassword456", refreshJwt: "yourRefreshJWT") +try await Descope.password.update(loginId: "andy@example.com", newPassword: "newSecurePassword456", refreshJwt: "yourRefreshJWT") ``` #### Replace Password @@ -329,7 +329,7 @@ try await descope.password.update(loginId: "andy@example.com", newPassword: "new To replace a user's password by providing their current password: ```swift -let authResponse = try await descope.password.replace(loginId: "andy@example.com", oldPassword: "SecurePassword123!", newPassword: "NewSecurePassword456!") +let authResponse = try await Descope.password.replace(loginId: "andy@example.com", oldPassword: "SecurePassword123!", newPassword: "NewSecurePassword456!") ``` #### Send Password Reset Email @@ -337,5 +337,5 @@ let authResponse = try await descope.password.replace(loginId: "andy@example.com Initiate a password reset by sending an email: ```swift -try await descope.password.sendReset(loginId: "andy@example.com", redirectURL: "exampleauthschema://my-app.com/handle-reset") +try await Descope.password.sendReset(loginId: "andy@example.com", redirectURL: "exampleauthschema://my-app.com/handle-reset") ``` From b8b6e108a4d91862b22fbc79bc2ac570cce192d1 Mon Sep 17 00:00:00 2001 From: Asaf Shen Date: Mon, 21 Aug 2023 14:13:55 +0300 Subject: [PATCH 4/4] small readme adjustments --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6837f3a..01a9844 100644 --- a/README.md +++ b/README.md @@ -313,7 +313,7 @@ let authResponse = try await Descope.password.signUp(loginId: "andy@example.com" Authenticate an existing user using a password: ```swift -let authResponse = try await Descope.password.signIn(loginId: "andy@example.com", password: "securePassword123") +let authResponse = try await Descope.password.signIn(loginId: "andy@example.com", password: "securePassword123!") ``` #### Update Password @@ -321,7 +321,7 @@ let authResponse = try await Descope.password.signIn(loginId: "andy@example.com" If you need to update a user's password: ```swift -try await Descope.password.update(loginId: "andy@example.com", newPassword: "newSecurePassword456", refreshJwt: "yourRefreshJWT") +try await Descope.password.update(loginId: "andy@example.com", newPassword: "newSecurePassword456!", refreshJwt: "user-refresh-jwt") ``` #### Replace Password