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

feat(auth): add passwordless request options for magiclink #3385

Merged
merged 1 commit into from
Nov 27, 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
4 changes: 2 additions & 2 deletions Amplify/Categories/Auth/AuthCategory+ClientBehavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extension AuthCategory: AuthCategoryBehavior {
username: String,
flow: AuthPasswordlessFlow,
redirectURL: String,
options: AuthPasswordlessMagicLinkRequest.Options? = nil
options: AuthSignInWithMagicLinkRequest.Options? = nil
) async throws -> AuthSignInResult {
try await plugin.signInWithMagicLink(
username: username,
Expand All @@ -103,7 +103,7 @@ extension AuthCategory: AuthCategoryBehavior {

public func confirmSignInWithMagicLink(
challengeResponse: String,
options: AuthPasswordlessMagicLinkRequest.Options? = nil
options: AuthConfirmSignInWithMagicLinkRequest.Options? = nil
) async throws -> AuthSignInResult {
try await plugin.confirmSignInWithMagicLink(
challengeResponse: challengeResponse,
Expand Down
4 changes: 2 additions & 2 deletions Amplify/Categories/Auth/AuthCategoryBehavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
username: String,
flow: AuthPasswordlessFlow,
redirectURL: String,
options: AuthPasswordlessMagicLinkRequest.Options?
options: AuthSignInWithMagicLinkRequest.Options?
) async throws -> AuthSignInResult

/// Confirms Sign in with Magiclink flow
Expand All @@ -172,7 +172,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
/// - options: Parameters specific to plugin behavior
func confirmSignInWithMagicLink(
challengeResponse: String,
options: AuthPasswordlessMagicLinkRequest.Options?
options: AuthConfirmSignInWithMagicLinkRequest.Options?
) async throws -> AuthSignInResult

/// Initiates Sign in with OTP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@

import Foundation

/// Request to sign in a user with Passwordless Magic Link flow
public struct AuthPasswordlessMagicLinkRequest: AmplifyOperationRequest {
/// Request to confirm sign in a user with magic link flow
public struct AuthConfirmSignInWithMagicLinkRequest: AmplifyOperationRequest {

/// Extra request options defined in `AuthPasswordlessMagicLinkRequest.Options`
/// The value of `challengeResponse` is the code that is received
/// by the user in magic link
public let challengeResponse: String

/// Extra request options defined in `AuthConfirmSignInWithMagicLinkRequest.Options`
public var options: Options

public init(options: Options) {
public init(challengeResponse: String, options: Options) {
self.challengeResponse = challengeResponse
self.options = options
}
}

public extension AuthPasswordlessMagicLinkRequest {
public extension AuthConfirmSignInWithMagicLinkRequest {

struct Options {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct AuthConfirmSignInWithOTPRequest: AmplifyOperationRequest {
/// The value of `challengeResponse`is the OTP that is received on the destination provided during sign in request
public let challengeResponse: String

/// Extra request options defined in `AuthPasswordlessOTPRequest.Options`
/// Extra request options defined in `AuthConfirmSignInWithOTPRequest.Options`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

public var options: Options

public init(challengeResponse: String, options: Options) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import Foundation

/// Request to sign in a user with Passwordless Magic Link flow
public struct AuthSignInWithMagicLinkRequest: AmplifyOperationRequest {

/// User name for which the magic link was requested
public let username: String

/// The flow that the request should begin with.
public let flow: AuthPasswordlessFlow

/// The redirect url that the magic link will be configured with
public let redirectURL: String

/// Extra request options defined in `AuthSignInWithMagicLinkRequest.Options`
public var options: Options

public init(username: String, flow: AuthPasswordlessFlow, redirectURL: String, options: Options) {
self.username = username
self.flow = flow
self.redirectURL = redirectURL
self.options = options
}
}

public extension AuthSignInWithMagicLinkRequest {

struct Options {

/// Extra plugin specific options, only used in special circumstances when the existing options do not provide
/// a way to utilize the underlying auth plugin functionality. See plugin documentation for expected
/// key/values
public let pluginOptions: Any?

public init(pluginOptions: Any? = nil) {
self.pluginOptions = pluginOptions
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ extension AWSCognitoAuthPlugin: AuthCategoryBehavior {
username: String,
flow: AuthPasswordlessFlow,
redirectURL: String,
options: AuthPasswordlessMagicLinkRequest.Options?
options: AuthSignInWithMagicLinkRequest.Options?
) async throws -> AuthSignInResult {
throw AuthError.unknown("Not Implemented")
}

public func confirmSignInWithMagicLink(
challengeResponse: String,
options: AuthPasswordlessMagicLinkRequest.Options?
options: AuthConfirmSignInWithMagicLinkRequest.Options?
) async throws -> AuthSignInResult {
throw AuthError.unknown("Not Implemented")
}
Expand Down
4 changes: 2 additions & 2 deletions AmplifyTestCommon/Mocks/MockAuthCategoryPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ class MockAuthCategoryPlugin: MessageReporter, AuthCategoryPlugin {
username: String,
flow: AuthPasswordlessFlow,
redirectURL: String,
options: AuthPasswordlessMagicLinkRequest.Options?
options: AuthSignInWithMagicLinkRequest.Options?
) async throws -> AuthSignInResult {
fatalError()
}

func confirmSignInWithMagicLink(
challengeResponse: String,
options: AuthPasswordlessMagicLinkRequest.Options?
options: AuthConfirmSignInWithMagicLinkRequest.Options?
) async throws -> AuthSignInResult {
fatalError()
}
Expand Down