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: added support for webview as a provider for webauth #875

Merged
merged 17 commits into from
Oct 14, 2024

Conversation

desusai7
Copy link
Contributor

📋 feat: added support for webview as a provider for webauth

  • Added WKWebView as a User Agent for WebAuthentication along with ASWebAuthenticationSession & SFSafariViewController

Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • [] I have added documentation for all new/changed functionality (or N/A)

🎯 Testing

  • Ensure that the WKWebView is working as a User Agent for performing the WebAuthentication

@desusai7 desusai7 self-assigned this Sep 26, 2024
@desusai7 desusai7 requested a review from a team as a code owner September 26, 2024 05:57
@@ -27,13 +27,15 @@ class ViewController: UIViewController {
@IBAction func login(_ sender: Any) {
Auth0
.webAuth()
.useWebViewProvider()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest adding a new static func to the WebAuthentication struct like https://github.com/auth0/Auth0.swift/blob/master/Auth0/SafariProvider.swift#L37, as that:

  • Follows the existing pattern in use for web providers
  • Avoids adding new useX() methods that have the disadvantage of being mutually exclusive (e.g. these can be chained and it's not clear which one will end up being used)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, changed accordingly

#if os(iOS)
private(set) var useWebViewProvider = false
private(set) var webViewProviderPresentationStyle: UIModalPresentationStyle = .fullScreen
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a func like https://github.com/auth0/Auth0.swift/blob/master/Auth0/SafariProvider.swift#L37 also has the advantage of being on its own (gated) file, so there's no need to have these conditionals here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed accordingly

let provider = self.provider ?? WebAuthentication.asProvider(redirectURL: redirectURL,
ephemeralSession: ephemeralSession)

#if os(iOS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed accordingly

Comment on lines 89 to 92
case .webViewNavigationFailed: return "An error occured during a committed main frame navigation of WebView"
case .webViewProvisionalNavigationFailed: return "An error occured while starting to load data for the main frame of WebView"
case .webViewContentProcessTerminated: return "WebView's content process is terminated."
case .webViewResourceLoadingStopped: return "WebView's resource loading has been stopped"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
case .webViewNavigationFailed: return "An error occured during a committed main frame navigation of WebView"
case .webViewProvisionalNavigationFailed: return "An error occured while starting to load data for the main frame of WebView"
case .webViewContentProcessTerminated: return "WebView's content process is terminated."
case .webViewResourceLoadingStopped: return "WebView's resource loading has been stopped"
case .webViewNavigationFailed: return "An error occurred during a committed main frame navigation of the WebView."
case .webViewProvisionalNavigationFailed: return "An error occurred while starting to load data for the main frame of the WebView."
case .webViewContentProcessTerminated: return "The WebView's content process was terminated."
case .webViewResourceLoadingStopped: return "The WebView's resource loading was stopped."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated accordingly

}

extension WebViewUserAgent {
var topViewController: UIViewController? {
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have this logic here: https://github.com/auth0/Auth0.swift/blob/master/Auth0/SafariProvider.swift#L50-L77
Maybe we can put it in some kind of shared helper (e.g. an internal static var added to UIWindow –analogous to rootViewController)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, moved this to a shared helper


static let customSchemeRedirectionSuccessMessage = "com.auth0.webview.redirection_success"
static let customSchemeRedirectionFailureMessage = "com.auth0.webview.redirection_failure"
let defaultSchemesSupportedByWKWebview = ["http", "https"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest checking with somebody from the security team if we should be supporting http schemes here (vs https only), e.g. when using an authorize URL override that proxies to Auth0.

NSLocalizedDescriptionKey: "WebViewProvider: WKURLSchemeHandler: Webview Resource Loading has been stopped"
])
urlSchemeTask.didFailWithError(error)
self.finish(with: .failure(WebAuthError(code: .webViewResourceLoadingStopped)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this error case be userCancelled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, updated accordingly

@fal3
Copy link

fal3 commented Oct 1, 2024

I've tested this on my local branch and it still does not fix my webview issue.

@desusai7
Copy link
Contributor Author

desusai7 commented Oct 3, 2024

I've tested this on my local branch and it still does not fix my webview issue.

Hi @fal3,

Can you please share more details about the webview issue you are running into ?

@fal3
Copy link

fal3 commented Oct 3, 2024

I've tested this on my local branch and it still does not fix my webview issue.

Hi @fal3,

Can you please share more details about the webview issue you are running into ?

We get this simulator crash 👇 . Which is also related to this incident

log.txt

@desusai7
Copy link
Contributor Author

desusai7 commented Oct 4, 2024

I've tested this on my local branch and it still does not fix my webview issue.

Hi @fal3,
Can you please share more details about the webview issue you are running into ?

We get this simulator crash 👇 . Which is also related to this incident

log.txt

@fal3, I would like to clarify that this pull request is not intended to address the issue you mentioned. Additionally, regarding the crash you are experiencing, could you please confirm if you were able to reproduce this issue on a real device as well?

@desusai7 desusai7 requested a review from Widcket October 4, 2024 05:39
@furrki
Copy link

furrki commented Oct 7, 2024

I've tested this on my local branch and it still does not fix my webview issue.

Hi @fal3,
Can you please share more details about the webview issue you are running into ?

We get this simulator crash 👇 . Which is also related to this incident
log.txt

@fal3, I would like to clarify that this pull request is not intended to address the issue you mentioned. Additionally, regarding the crash you are experiencing, could you please confirm if you were able to reproduce this issue on a real device as well?

I can confirm that this issue happens only on simulator.

}

describe("initialization") {
it("should initialize with correct parameters") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a test case that uses returnTo instead of redirect_uri?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, added it now

@desusai7 desusai7 requested a review from Widcket October 9, 2024 12:29
Widcket
Widcket previously approved these changes Oct 9, 2024
@desusai7 desusai7 requested a review from Widcket October 14, 2024 04:38
@desusai7 desusai7 merged commit 2edbb4f into master Oct 14, 2024
15 checks passed
@desusai7 desusai7 deleted the feat/webview_support branch October 14, 2024 08:48
@desusai7 desusai7 mentioned this pull request Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants