Skip to content

Conversation

@selanthiraiyan
Copy link
Contributor

@selanthiraiyan selanthiraiyan commented Dec 14, 2022

Part of: #8394

Description

  • Adds an implementation of ApplicationPasswordUseCase that works with WPCOM credentials.
  • Unit tests will be added in a future PR.

Testing instructions

  • CI passing should be enough.
  • The use case will be used in future PRs. No testing steps available now.

Screenshots

NA


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@selanthiraiyan selanthiraiyan changed the title [REST API]: Use case to generate and delete Application password [REST API] Use case to generate and delete Application password Dec 14, 2022
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Dec 14, 2022

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr8400-cd306a2 on your iPhone

If you need access to App Center, please ask a maintainer to add you.

///
private var applicationPasswordName: String {
get async {
await UIDevice.current.model
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the internal discussion [p1669977432588639/1669965496.085079-slack-C046HDZL87J], we should name the application in the following format: <bundle-id>.ios-app-client.<model-name>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in d905e7a

init(siteID: Int64,
networkcredentials: Credentials,
network: Network? = nil,
keychain: Keychain = Keychain(service: "com.automattic.woocommerce.applicationpassword")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use the same service name for Keychain in the whole app: WooConstants.keychainServiceName.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 6b63664

import Foundation
import Alamofire

public class ApplicationPasswordNetwork: Network {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a comment explaining why this network is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in b2f3d74

}
}

@available(*, deprecated, message: "Not implemented. Use the `Result` based method instead.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use unavailable instead of deprecated since that fits this situation better.

Suggested change
@available(*, deprecated, message: "Not implemented. Use the `Result` based method instead.")
@available(*, unavailable, message: "Not implemented. Use the `Result` based method instead.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using unavailable will make the method unavailable, which makes ApplicationPasswordNetwork not satisfy the Network protocol requirements.

@available(*, deprecated, message: "Not implemented. Use the `Result` based method instead.")
public func responseData(for request: URLRequestConvertible, completion: @escaping (Data?, Error?) -> Void) { }

@available(*, deprecated, message: "Not implemented. Use the `Result` based method instead.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the above comment:

Suggested change
@available(*, deprecated, message: "Not implemented. Use the `Result` based method instead.")
@available(*, unavailable, message: "Not implemented. Use the `Result` based method instead.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Empty<Swift.Result<Data, Error>, Never>().eraseToAnyPublisher()
}

@available(*, deprecated, message: "Not implemented")
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the above comment:

Suggested change
@available(*, deprecated, message: "Not implemented")
@available(*, unavailable, message: "Not implemented")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/// - Returns: Generated `ApplicationPassword` instance
///
func generateNewPassword() async throws -> ApplicationPassword {
let password = try await createApplicationPasswordUsingWPCOMAuthToken()
Copy link
Contributor

@itsmeichigo itsmeichigo Dec 14, 2022

Choose a reason for hiding this comment

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

Should we handle deleting and generating the password again within this use case, or do you think it's better that it's handled from the outside? I just thought it would be more straightforward for the consumer of this use case to not have to call this method twice in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. Started deleting the existing password when duplicate name error occurs - 38c7dec

@selanthiraiyan selanthiraiyan added this to the 11.7 milestone Dec 14, 2022
@selanthiraiyan selanthiraiyan added type: task An internally driven task. feature: login Related to any part of the log in or sign in flow, or authentication. labels Dec 14, 2022
@selanthiraiyan selanthiraiyan marked this pull request as ready for review December 14, 2022 08:01
@itsmeichigo itsmeichigo self-assigned this Dec 14, 2022
Copy link
Contributor

@itsmeichigo itsmeichigo left a comment

Choose a reason for hiding this comment

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

Thanks for the quick updates! Everything looks good to me now 🚀

@mokagio
Copy link
Contributor

mokagio commented Dec 15, 2022

@itsmeichigo @selanthiraiyan merging #8418 here should solve the CI issue

Add missing `networking_pods` dependencies to Yosemite in `Podfile`
@selanthiraiyan selanthiraiyan merged commit c5aafe4 into trunk Dec 15, 2022
@selanthiraiyan selanthiraiyan deleted the feat/8394-generate-application-password branch December 15, 2022 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: login Related to any part of the log in or sign in flow, or authentication. type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants