-
Notifications
You must be signed in to change notification settings - Fork 31
Handle https callback url #524
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
Changes from all commits
3bf1c55
d7557fb
5b30563
29a89f4
bb4f427
6c24b1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,9 @@ struct QuickEditor<ImageEditor: ImageEditorView>: View { | |
| self.avatarUpdatedHandler = avatarUpdatedHandler | ||
| } | ||
|
|
||
| let authorizationFinishedNotification = NotificationCenter.default.publisher(for: .authorizationFinished) | ||
| let authorizationErrorNotification = NotificationCenter.default.publisher(for: .authorizationError) | ||
|
|
||
| var body: some View { | ||
| NavigationView { | ||
| if let token { | ||
|
|
@@ -63,6 +66,12 @@ struct QuickEditor<ImageEditor: ImageEditorView>: View { | |
| noticeView() | ||
| .accumulateIntrinsicHeight() | ||
| } | ||
| }.onReceive(authorizationFinishedNotification) { _ in | ||
| onAuthenticationFinished() | ||
| }.onReceive(authorizationErrorNotification) { notification in | ||
| guard let error = notification.object as? OAuthError else { return } | ||
| oauthError = error | ||
| onAuthenticationFinished() | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -131,8 +140,7 @@ struct QuickEditor<ImageEditor: ImageEditorView>: View { | |
| isAuthenticating = true | ||
| if !oauthSession.hasValidSession(with: email) { | ||
| do { | ||
| _ = try await oauthSession.retrieveAccessToken(with: email) | ||
| oauthError = nil | ||
| try await oauthSession.retrieveAccessToken(with: email) | ||
| } catch OAuthError.oauthResponseError(_, let code) where code == .canceledLogin { | ||
| // ignore the error if the user has cancelled the operation. | ||
| } catch let error as OAuthError { | ||
|
|
@@ -141,9 +149,16 @@ struct QuickEditor<ImageEditor: ImageEditorView>: View { | |
| oauthError = nil | ||
| } | ||
| } | ||
| fetchedToken = oauthSession.sessionToken(with: email)?.token | ||
| isAuthenticating = false | ||
| onAuthenticationFinished() | ||
| } | ||
| } | ||
|
|
||
| func onAuthenticationFinished() { | ||
| if let fetchedToken = oauthSession.sessionToken(with: email)?.token { | ||
| self.fetchedToken = fetchedToken | ||
| oauthError = nil | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When ❓ Since we're already setting
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the problem here, is that when the Maybe what you described will handle all cases properly, but I'd be extra careful testing every success and error case (also a success after an error screen), if there's any change here. |
||
| } | ||
| isAuthenticating = false | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Just wondering why the manual cancel() is necessary? Doesn't the oauth session end itself once it's successful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the callback URL comes from universal links, the oauth session never returns, so it's never a "success", and the OAuth web view won't dismiss.
As every real scenario will use
httpsand universal link, it will always need this manual cancelling, so I think it safer to call it always, though is not necessary for our particular case of the demo app with the custom scheme exclusion.Testing the demo app, it didn't seem to be a problem, so I decided to keep the logic simple.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the canceling, the web view stays like this without dismissing:

So the canceling is basically the simplest way I found to dismiss it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, interesting. Thanks!