-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
278 additions
and
83 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
41 changes: 41 additions & 0 deletions
41
Amplify/Categories/Auth/Request/AuthAttributeSendVerificationCodeRequest.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,41 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
// swiftlint:disable type_name | ||
|
||
/// Request for sending verification code that was generated for update attribute | ||
public struct AuthSendUserAttributeVerificationCodeRequest: AmplifyOperationRequest { | ||
|
||
/// Attribute key for which the confirmation code was sent | ||
public let attributeKey: AuthUserAttributeKey | ||
|
||
/// Extra request options defined in `AuthSendUserAttributeVerificationCodeRequest.Options` | ||
public var options: Options | ||
|
||
public init(attributeKey: AuthUserAttributeKey, | ||
options: Options) { | ||
self.attributeKey = attributeKey | ||
self.options = options | ||
} | ||
} | ||
|
||
public extension AuthSendUserAttributeVerificationCodeRequest { | ||
|
||
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 | ||
} | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
...ces/AWSCognitoAuthPlugin/Models/Options/AWSSendUserAttributeVerificationCodeOptions.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,25 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
public struct AWSSendUserAttributeVerificationCodeOptions { | ||
|
||
/// A map of custom key-value pairs that you can provide as input for any custom workflows that this action triggers. | ||
/// | ||
/// When you use the ResendConfirmationCode API action, Amazon Cognito invokes the function that is assigned to the custom message trigger. | ||
/// When Amazon Cognito invokes this function, it passes a JSON payload, which the function receives as input. | ||
/// This payload contains a clientMetadata attribute, which provides the data that you assigned to the ClientMetadata parameter in your GetUserAttributeVerificationCode request. | ||
/// In your function code in AWS Lambda, you can process the clientMetadata value to enhance your workflow for your specific needs. | ||
/// | ||
/// For more information, see Customizing user pool Workflows with Lambda Triggers in the Amazon Cognito Developer Guide. | ||
public let metadata: [String: String]? | ||
|
||
public init(metadata: [String: String]? = nil) { | ||
self.metadata = metadata | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ognitoAuthPlugin/Task/Protocols/UserTasks/AuthSendUserAttributeVerificationCodeTask.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,16 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Amplify | ||
|
||
protocol AuthSendUserAttributeVerificationCodeTask: AmplifyAuthTask where Request == AuthSendUserAttributeVerificationCodeRequest, Success == AuthCodeDeliveryDetails, Failure == AuthError {} | ||
|
||
public extension HubPayload.EventName.Auth { | ||
|
||
/// eventName for HubPayloads emitted by this operation | ||
static let sendUserAttributeVerificationCodeAPI = "Auth.sendUserAttributeVerificationCodeAPI" | ||
} |
67 changes: 67 additions & 0 deletions
67
...es/AWSCognitoAuthPlugin/Task/UserTasks/AWSAuthSendUserAttributeVerificationCodeTask.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,67 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
import Amplify | ||
import AWSPluginsCore | ||
import AWSCognitoIdentityProvider | ||
|
||
class AWSAuthSendUserAttributeVerificationCodeTask: AuthSendUserAttributeVerificationCodeTask { | ||
typealias CognitoUserPoolFactory = () throws -> CognitoUserPoolBehavior | ||
|
||
private let request: AuthSendUserAttributeVerificationCodeRequest | ||
private let authStateMachine: AuthStateMachine | ||
private let userPoolFactory: CognitoUserPoolFactory | ||
private let taskHelper: AWSAuthTaskHelper | ||
|
||
var eventName: HubPayloadEventName { | ||
HubPayload.EventName.Auth.sendUserAttributeVerificationCodeAPI | ||
} | ||
|
||
init(_ request: AuthSendUserAttributeVerificationCodeRequest, | ||
authStateMachine: AuthStateMachine, | ||
userPoolFactory: @escaping CognitoUserPoolFactory) { | ||
self.request = request | ||
self.authStateMachine = authStateMachine | ||
self.userPoolFactory = userPoolFactory | ||
self.taskHelper = AWSAuthTaskHelper(authStateMachine: authStateMachine) | ||
} | ||
|
||
func execute() async throws -> AuthCodeDeliveryDetails { | ||
do { | ||
await taskHelper.didStateMachineConfigured() | ||
let accessToken = try await taskHelper.getAccessToken() | ||
let devices = try await initiateGettingVerificationCode(with: accessToken) | ||
return devices | ||
} catch let error as AuthErrorConvertible { | ||
throw error.authError | ||
} catch { | ||
throw AuthError.configuration( | ||
"Unable to execute auth task", | ||
AuthPluginErrorConstants.configurationError, | ||
error | ||
) | ||
} | ||
} | ||
|
||
func initiateGettingVerificationCode(with accessToken: String) async throws -> AuthCodeDeliveryDetails { | ||
let userPoolService = try userPoolFactory() | ||
let clientMetaData = (request.options.pluginOptions as? AWSSendUserAttributeVerificationCodeOptions)?.metadata ?? [:] | ||
|
||
let input = GetUserAttributeVerificationCodeInput( | ||
accessToken: accessToken, | ||
attributeName: request.attributeKey.rawValue, | ||
clientMetadata: clientMetaData) | ||
|
||
let result = try await userPoolService.getUserAttributeVerificationCode(input: input) | ||
guard let deliveryDetails = result.codeDeliveryDetails?.toAuthCodeDeliveryDetails() else { | ||
let authError = AuthError.unknown("Unable to get Auth code delivery details", nil) | ||
throw authError | ||
} | ||
return deliveryDetails | ||
} | ||
} |
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.