Skip to content

Commit

Permalink
feat(auth): Update public API request and options parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisabhash committed Nov 20, 2023
1 parent 4d940a6 commit 99256c1
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 15 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: AuthPasswordlessRequest.Options?
) async throws -> AuthSignInResult {
try await plugin.signInWithMagicLink(username: username, flow: flow, redirectURL: redirectURL, options: options)
}

public func confirmSignInWithMagicLink(
challengeResponse: String,
options: AuthConfirmSignInRequest.Options?
options: AuthPasswordlessRequest.Options?
) 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: AuthPasswordlessRequest.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: AuthPasswordlessRequest.Options?
) async throws -> AuthSignInResult

}
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
34 changes: 34 additions & 0 deletions Amplify/Categories/Auth/Request/AuthPasswordlessRequest.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 Magic Link
public struct AuthPasswordlessRequest: AmplifyOperationRequest {

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

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

public extension AuthPasswordlessRequest {

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

public func confirmSignInWithMagicLink(
challengeResponse: String,
options: AuthConfirmSignInRequest.Options?
options: AuthPasswordlessRequest.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 @@ -110,11 +110,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: AuthPasswordlessRequest.Options?) async throws -> AuthSignInResult {
fatalError()
}

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

Expand Down

0 comments on commit 99256c1

Please sign in to comment.