Skip to content

Commit

Permalink
Merge branch 'main' into login-options
Browse files Browse the repository at this point in the history
  • Loading branch information
itaihanski authored Sep 5, 2023
2 parents 1b7a80c + 79ed088 commit 1cf0234
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,49 @@ code the app produces.
```swift
let authResponse = try await Descope.totp.verify(loginId: "[email protected]", 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: "[email protected]", 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: "[email protected]", password: "securePassword123!")
```

#### Update Password

If you need to update a user's password:

```swift
try await Descope.password.update(loginId: "[email protected]", newPassword: "newSecurePassword456!", refreshJwt: "user-refresh-jwt")
```

#### Replace Password

To replace a user's password by providing their current password:

```swift
let authResponse = try await Descope.password.replace(loginId: "[email protected]", oldPassword: "SecurePassword123!", newPassword: "NewSecurePassword456!")
```

#### Send Password Reset Email

Initiate a password reset by sending an email:

```swift
try await Descope.password.sendReset(loginId: "[email protected]", redirectURL: "exampleauthschema://my-app.com/handle-reset")
```
4 changes: 2 additions & 2 deletions src/internal/http/DescopeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,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,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/routes/Password.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/sdk/Callbacks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,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, Error>) -> Void) {
/// - Returns: An ``AuthenticationResponse`` value upon successful replacement and authentication.
func replace(loginId: String, oldPassword: String, newPassword: String, completion: @escaping (Result<AuthenticationResponse, Error>) -> Void) {
Task {
do {
completion(.success(try await replace(loginId: loginId, oldPassword: oldPassword, newPassword: newPassword)))
Expand Down
3 changes: 2 additions & 1 deletion src/sdk/Routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,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 replacement and authentication.
func replace(loginId: String, oldPassword: String, newPassword: String) async throws -> AuthenticationResponse

/// Sends a password reset email to the user.
///
Expand Down

0 comments on commit 1cf0234

Please sign in to comment.