-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #380 from stytchauth/password-discovery
Add password discovery
- Loading branch information
Showing
49 changed files
with
950 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
.../Generated/StytchB2BClient.Passwords.Discovery.authenticate+AsyncVariants.generated.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Generated using Sourcery 2.0.2 — https://github.com/krzysztofzablocki/Sourcery | ||
// DO NOT EDIT | ||
import Combine | ||
import Foundation | ||
|
||
public extension StytchB2BClient.Passwords.Discovery { | ||
/// Authenticate an email/password combination in the discovery flow. | ||
/// This authenticate flow is only valid for cross-org passwords use cases, and is not tied to a specific organization. | ||
func authenticate(parameters: AuthenticateParameters, completion: @escaping Completion<StytchB2BClient.DiscoveryAuthenticateResponse>) { | ||
Task { | ||
do { | ||
completion(.success(try await authenticate(parameters: parameters))) | ||
} catch { | ||
completion(.failure(error)) | ||
} | ||
} | ||
} | ||
|
||
/// Authenticate an email/password combination in the discovery flow. | ||
/// This authenticate flow is only valid for cross-org passwords use cases, and is not tied to a specific organization. | ||
func authenticate(parameters: AuthenticateParameters) -> AnyPublisher<StytchB2BClient.DiscoveryAuthenticateResponse, Error> { | ||
return Deferred { | ||
Future({ promise in | ||
Task { | ||
do { | ||
promise(.success(try await authenticate(parameters: parameters))) | ||
} catch { | ||
promise(.failure(error)) | ||
} | ||
} | ||
}) | ||
} | ||
.eraseToAnyPublisher() | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../Generated/StytchB2BClient.Passwords.Discovery.resetByEmail+AsyncVariants.generated.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Generated using Sourcery 2.0.2 — https://github.com/krzysztofzablocki/Sourcery | ||
// DO NOT EDIT | ||
import Combine | ||
import Foundation | ||
|
||
public extension StytchB2BClient.Passwords.Discovery { | ||
/// Reset the password associated with an email and start an intermediate session. | ||
/// This endpoint checks that the password reset token is valid, hasn’t expired, or already been used. | ||
func resetByEmail(parameters: ResetByEmailParameters, completion: @escaping Completion<StytchB2BClient.DiscoveryAuthenticateResponse>) { | ||
Task { | ||
do { | ||
completion(.success(try await resetByEmail(parameters: parameters))) | ||
} catch { | ||
completion(.failure(error)) | ||
} | ||
} | ||
} | ||
|
||
/// Reset the password associated with an email and start an intermediate session. | ||
/// This endpoint checks that the password reset token is valid, hasn’t expired, or already been used. | ||
func resetByEmail(parameters: ResetByEmailParameters) -> AnyPublisher<StytchB2BClient.DiscoveryAuthenticateResponse, Error> { | ||
return Deferred { | ||
Future({ promise in | ||
Task { | ||
do { | ||
promise(.success(try await resetByEmail(parameters: parameters))) | ||
} catch { | ||
promise(.failure(error)) | ||
} | ||
} | ||
}) | ||
} | ||
.eraseToAnyPublisher() | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...rated/StytchB2BClient.Passwords.Discovery.resetByEmailStart+AsyncVariants.generated.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Generated using Sourcery 2.0.2 — https://github.com/krzysztofzablocki/Sourcery | ||
// DO NOT EDIT | ||
import Combine | ||
import Foundation | ||
|
||
public extension StytchB2BClient.Passwords.Discovery { | ||
/// Initiates a password reset for the email address provided, when cross-org passwords are enabled. | ||
/// This will trigger an email to be sent to the address, containing a magic link that will allow them to set a new password and authenticate. | ||
func resetByEmailStart(parameters: ResetByEmailStartParameters, completion: @escaping Completion<BasicResponse>) { | ||
Task { | ||
do { | ||
completion(.success(try await resetByEmailStart(parameters: parameters))) | ||
} catch { | ||
completion(.failure(error)) | ||
} | ||
} | ||
} | ||
|
||
/// Initiates a password reset for the email address provided, when cross-org passwords are enabled. | ||
/// This will trigger an email to be sent to the address, containing a magic link that will allow them to set a new password and authenticate. | ||
func resetByEmailStart(parameters: ResetByEmailStartParameters) -> AnyPublisher<BasicResponse, Error> { | ||
return Deferred { | ||
Future({ promise in | ||
Task { | ||
do { | ||
promise(.success(try await resetByEmailStart(parameters: parameters))) | ||
} catch { | ||
promise(.failure(error)) | ||
} | ||
} | ||
}) | ||
} | ||
.eraseToAnyPublisher() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
...hCore/StytchB2BClient/StytchB2BClient+Passwords/StytchB2BClient+Passwords+Discovery.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import Foundation | ||
|
||
public extension StytchB2BClient.Passwords { | ||
/// The interface for interacting with otp email discovery products. | ||
var discovery: Discovery { | ||
.init(router: router.scopedRouter { | ||
$0.discovery | ||
}) | ||
} | ||
} | ||
|
||
public extension StytchB2BClient.Passwords { | ||
struct Discovery { | ||
let router: NetworkingRouter<StytchB2BClient.PasswordsRoute.DiscoveryRoute> | ||
|
||
@Dependency(\.pkcePairManager) private var pkcePairManager | ||
@Dependency(\.sessionManager) private var sessionManager | ||
|
||
// sourcery: AsyncVariants, (NOTE: - must use /// doc comment styling) | ||
/// Initiates a password reset for the email address provided, when cross-org passwords are enabled. | ||
/// This will trigger an email to be sent to the address, containing a magic link that will allow them to set a new password and authenticate. | ||
public func resetByEmailStart(parameters: ResetByEmailStartParameters) async throws -> BasicResponse { | ||
let pkcePair = try pkcePairManager.generateAndReturnPKCECodePair() | ||
return try await router.post( | ||
to: .resetByEmailStart, | ||
parameters: CodeChallengedParameters( | ||
codingPrefix: .pkce, | ||
codeChallenge: pkcePair.codeChallenge, | ||
codeChallengeMethod: pkcePair.method, | ||
wrapped: parameters | ||
), | ||
useDFPPA: true | ||
) | ||
} | ||
|
||
// sourcery: AsyncVariants, (NOTE: - must use /// doc comment styling) | ||
/// Reset the password associated with an email and start an intermediate session. | ||
/// This endpoint checks that the password reset token is valid, hasn’t expired, or already been used. | ||
public func resetByEmail(parameters: ResetByEmailParameters) async throws -> StytchB2BClient.DiscoveryAuthenticateResponse { | ||
defer { | ||
try? pkcePairManager.clearPKCECodePair() | ||
} | ||
|
||
guard let pkcePair: PKCECodePair = pkcePairManager.getPKCECodePair() else { | ||
throw StytchSDKError.missingPKCE | ||
} | ||
|
||
let intermediateSessionTokenParameters = IntermediateSessionTokenParameters( | ||
intermediateSessionToken: sessionManager.intermediateSessionToken, | ||
wrapped: CodeVerifierParameters( | ||
codingPrefix: .pkce, | ||
codeVerifier: pkcePair.codeVerifier, | ||
wrapped: parameters | ||
) | ||
) | ||
|
||
return try await router.post( | ||
to: .resetByEmail, | ||
parameters: intermediateSessionTokenParameters, | ||
useDFPPA: true | ||
) | ||
} | ||
|
||
// sourcery: AsyncVariants, (NOTE: - must use /// doc comment styling) | ||
/// Authenticate an email/password combination in the discovery flow. | ||
/// This authenticate flow is only valid for cross-org passwords use cases, and is not tied to a specific organization. | ||
public func authenticate(parameters: AuthenticateParameters) async throws -> StytchB2BClient.DiscoveryAuthenticateResponse { | ||
try await router.post( | ||
to: .authenticate, | ||
parameters: parameters, | ||
useDFPPA: true | ||
) | ||
} | ||
} | ||
} | ||
|
||
public extension StytchB2BClient.Passwords.Discovery { | ||
struct ResetByEmailStartParameters: Encodable, Sendable { | ||
let emailAddress: String | ||
let discoveryRedirectUrl: URL? | ||
let resetPasswordRedirectUrl: URL? | ||
let resetPasswordExpirationMinutes: Minutes? | ||
let resetPasswordTemplateId: String? | ||
|
||
/// - Parameters: | ||
/// - emailAddress: The email that requested the password reset. | ||
/// - discoveryRedirectUrl: The URL that the Member clicks from the password reset email to skip resetting their | ||
/// password and directly log in. This should be a URL that your app receives, parses, and subsequently sends an API | ||
/// request to the magic link authenticate endpoint to complete the login process without resetting their password. | ||
/// If this value is not passed, the login redirect URL that you set in your Dashboard is used. If you have not set | ||
/// a default login redirect URL, an error is returned. | ||
/// - resetPasswordRedirectUrl: The URL that the Member clicks from the password reset email to finish the reset password | ||
/// flow. This should be a URL that your app receives and parses before showing your app's reset password page. After | ||
/// the Member submits a new password to your app, it should send an API request to complete the password reset process. | ||
/// If this value is not passed, the default reset password redirect URL that you set in your Dashboard is used. If you | ||
/// have not set a default reset password redirect URL, an error is returned. | ||
/// - resetPasswordExpirationMinutes: Set the expiration for the password reset, in minutes. By default, it expires in | ||
/// 30 minutes. The minimum expiration is 5 minutes, and the maximum is 7 days (10080 minutes). | ||
/// - resetPasswordTemplateId: The email template ID to use for password reset. If not provided, your default email | ||
/// template will be sent. If providing a template ID, it must be either a template using Stytch's customizations or a | ||
/// Passwords reset custom HTML template. | ||
public init( | ||
emailAddress: String, | ||
discoveryRedirectUrl: URL? = nil, | ||
resetPasswordRedirectUrl: URL? = nil, | ||
resetPasswordExpirationMinutes: Minutes = .defaultSessionDuration, | ||
resetPasswordTemplateId: String? = nil | ||
) { | ||
self.emailAddress = emailAddress | ||
self.discoveryRedirectUrl = discoveryRedirectUrl | ||
self.resetPasswordRedirectUrl = resetPasswordRedirectUrl | ||
self.resetPasswordExpirationMinutes = resetPasswordExpirationMinutes | ||
self.resetPasswordTemplateId = resetPasswordTemplateId | ||
} | ||
} | ||
|
||
struct ResetByEmailParameters: Encodable, Sendable { | ||
let passwordResetToken: String | ||
let password: String | ||
|
||
/// - Parameters: | ||
/// - passwordResetToken: The token to authenticate. | ||
/// - password: The new password for the Member. | ||
public init(passwordResetToken: String, password: String) { | ||
self.passwordResetToken = passwordResetToken | ||
self.password = password | ||
} | ||
} | ||
|
||
struct AuthenticateParameters: Encodable, Sendable { | ||
let emailAddress: String | ||
let password: String | ||
|
||
/// - Parameters: | ||
/// - emailAddress: The email attempting to login. | ||
/// - password: The password for the email address. | ||
public init(emailAddress: String, password: String) { | ||
self.emailAddress = emailAddress | ||
self.password = password | ||
} | ||
} | ||
} | ||
|
||
public extension StytchB2BClient.Passwords.Discovery {} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.