-
Notifications
You must be signed in to change notification settings - Fork 232
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
Fix Dismiss AS/SF authentication sessions upon deep-link callback #281
Fix Dismiss AS/SF authentication sessions upon deep-link callback #281
Conversation
Can you add detailed, test steps please. Will have someone validate this. Thanks |
@cysp please can you add a before / after video so I can see your testing in action. Thanks |
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.
Looks okay, follow up comments in main section.
Hi @cocojoe, sorry for the radio silence. 😬 |
Sure that's fine. 👍 |
Hi @cocojoe, I've finally gotten around to taking those screen recordings and have sent them through to the email address used in your commits in this repo. |
Thanks, videos look fine. Can you rebase your branch please. |
fb0ad1a
to
8dd65bd
Compare
Cool, rebased. 🙂 |
@@ -29,14 +29,46 @@ import AuthenticationServices | |||
#if swift(>=3.2) | |||
@available(iOS 11.0, *) | |||
class SafariAuthenticationSession: AuthSession { | |||
private enum AuthenticationSession { |
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.
Can we use a regular class/struct instead of an enum?
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.
What kind of design do you have in mind using a class or struct?
Also is there a rationale for avoiding enumerations? They're a first-class type in Swift and this use-case seems like a perfect fit for an enumeration.
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 dont see it as a natural use of an enum or us having more options than these two, maybe something like this:
struct NativeAuthSession {
@available(iOS 12.0, *)
private var authServiceSession: ASWebAuthenticationSession?
private var safariSession: SFAuthenticationSession?
@available(iOS 12.0, *)
init(_ session: ASWebAuthenticationSession) {
this.authServiceSession = session;
}
init(_ session: SFAuthenticationSession) {
this.safariSession = session;
}
func start() -> Bool {
if #available(iOS 12.0, *) {
this.authServiceSession.start();
} else {
this.safariServices.start();
}
}
func cancel() {
if #available(iOS 12.0, *) {
this.authServiceSession?.cancel();
} else {
this.safariServices?.cancel();
}
}
}
(might have typos since I coded it on the GH UI)
But probably is going into too mich details
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.
The way I see it, we have the situation where we know that an object is one of two types, and that we will only have one, not both of those types of object. To me this seems like a perfect fit for an enum, since we can encode the fact that there's exactly one of those objects, and the type of that object into the type system.
The design where a struct has multiple optional properties feels like a less good fit because the type system admits the possibility that both of those properties may be nil (or not nil) at the same time, and requires unwrapping the optional in order to operate on the contained object.
Is there a style guide or a reason that you would prefer not to use an enum for this use case?
@cysp ☝️ |
8dd65bd
to
1f3c192
Compare
1f3c192
to
d1cbd9c
Compare
Sure, I've rebased onto master and it looks good to me. |
…th0#281) * Abstract over SF and AS authentication sessions * Pass cancellation to authentication sessions * Cancel authentication session upon completion
Changes
Cancel any active
ASWebAuthenticationSession
ofSFAuthenticationSession
when completing via a deep-link callback.Currently this scenario results in a crash due to messaging a deallocated authentication session object, as reported in #213
Technical implementation:
ASWebAuthenticationSession
or aSFAuthenticationSession
, exposing their common APISafariAuthenticationSession
, overrideAuthSession
's implementation ofresume(_:options:)
, forwarding toAuthSession
and, if successfully resumed, dismissing the relevant authentication sessioncancel()
to dismiss the authentication sessionReferences
Testing
I couldn't see any existing test suite for this functionality so I tried to write some to cover the completion / cancellation logic but I have not had any success. 😕
To manually test this, configure an Auth0 tenant with passwordless authentication via email and attempt to sign in using the link in the email.
I haven't executed the
!swift(>3.2)
branches here, but I didn't think that I should just abandon them, nor remove them in this PR. 🙃Checklist