Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace password session #43

Merged
merged 4 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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,
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 @@ -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, 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 @@ -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 replacement and authentication.
func replace(loginId: String, oldPassword: String, newPassword: String) async throws -> AuthenticationResponse

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