Skip to content

Commit

Permalink
feat(auth): Update public API request and options parameters (#3373)
Browse files Browse the repository at this point in the history
* feat(auth): Update public API request and options parameters

* Update comments

* Address review comments
  • Loading branch information
thisisabhash committed Dec 13, 2023
1 parent f857a08 commit a3288d4
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 16 deletions.
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,14 +92,14 @@ extension AuthCategory: AuthCategoryBehavior {
username: String,
flow: AuthPasswordlessFlow,
redirectURL: String,
options: AuthSignInRequest.Options?
options: AuthPasswordlessMagicLinkRequest.Options? = nil
) async throws -> AuthSignInResult {
try await plugin.signInWithMagicLink(username: username, flow: flow, redirectURL: redirectURL, options: options)
}

public func confirmSignInWithMagicLink(
challengeResponse: String,
options: AuthConfirmSignInRequest.Options?
options: AuthPasswordlessMagicLinkRequest.Options? = nil
) async throws -> AuthSignInResult {
try await plugin.confirmSignInWithMagicLink(challengeResponse: challengeResponse, options: options)
}
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: AuthSignInRequest.Options?
options: AuthPasswordlessMagicLinkRequest.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: AuthConfirmSignInRequest.Options?
options: AuthPasswordlessMagicLinkRequest.Options?
) async throws -> AuthSignInResult

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import Foundation
/// Delivery destination for the Auth Passwordless flows
///
public enum AuthPasswordlessDeliveryDestination {
case phone
case sms
case email
}
14 changes: 7 additions & 7 deletions Amplify/Categories/Auth/Models/AuthPasswordlessFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import Foundation

/// Auth Passwordless flow types
///
/// `.signUpAndSignIn` will create a new user and initiate signing in the user
/// `.signIn` will initiate signing in an existing user


public enum AuthPasswordlessFlow {
case signUpAndSignIn(
userAttributes: [String: String]?,
clientMetadata: [String: String]?
)
case signIn(clientMetadata: [String: String]?)
/// `.signUpAndSignIn` will create a new user and initiate signing in the user
case signUpAndSignIn

/// `.signIn` will initiate signing in an existing user
case signIn
}
7 changes: 7 additions & 0 deletions Amplify/Categories/Auth/Models/AuthSignInStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public enum AuthSignInStep {
/// Auth step that required the user to be confirmed
///
case confirmSignUp(AdditionalInfo?)

/// Auth Passwordless
/// Confirm sign in with OTP
case confirmSignInWithOTP(AuthCodeDeliveryDetails, AdditionalInfo?)

/// Confirm sign in with magic link
case confirmSignInWithMagicLink(AuthCodeDeliveryDetails, AdditionalInfo?)

/// There is no next step and the signIn flow is complete
///
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// 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 AuthPasswordlessMagicLinkRequest: AmplifyOperationRequest {

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

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

public extension AuthPasswordlessMagicLinkRequest {

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
}
}
}
34 changes: 34 additions & 0 deletions Amplify/Categories/Auth/Request/AuthPasswordlessOTPRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// 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 OTP flow
public struct AuthPasswordlessOTPRequest: AmplifyOperationRequest {

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

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

public extension AuthPasswordlessOTPRequest {

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: AuthSignInRequest.Options?
options: AuthPasswordlessMagicLinkRequest.Options?
) async throws -> AuthSignInResult {
throw AuthError.unknown("Not Implemented")
}

public func confirmSignInWithMagicLink(
challengeResponse: String,
options: AuthConfirmSignInRequest.Options?
options: AuthPasswordlessMagicLinkRequest.Options?
) async throws -> AuthSignInResult {
throw AuthError.unknown("Not Implemented")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
import Foundation

public struct AWSAuthSignInPasswordlessOptions {

public let clientMetadata: [String: String]?

public init(clientMetadata: [String: String]? = nil) {
self.clientMetadata = clientMetadata
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
import Foundation

public struct AWSAuthSignUpAndSignInPasswordlessOptions {

public let userAttributes: [String: String]?
public let clientMetadata: [String: String]?

public init(userAttributes: [String: String]? = nil,
clientMetadata: [String: String]? = nil) {
self.userAttributes = userAttributes
self.clientMetadata = clientMetadata
}

}
4 changes: 2 additions & 2 deletions AmplifyTestCommon/Mocks/MockAuthCategoryPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ class MockAuthCategoryPlugin: MessageReporter, AuthCategoryPlugin {
fatalError()
}

func signInWithMagicLink(username: String, flow: AuthPasswordlessFlow, redirectURL: String, options: AuthSignInRequest.Options?) async throws -> AuthSignInResult {
func signInWithMagicLink(username: String, flow: AuthPasswordlessFlow, redirectURL: String, options: AuthPasswordlessMagicLinkRequest.Options?) async throws -> AuthSignInResult {
fatalError()
}

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

Expand Down

0 comments on commit a3288d4

Please sign in to comment.