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

Bug 1317580 - Add additional deeplink support for FxA #2249

Merged
merged 4 commits into from Dec 13, 2016

Conversation

@vbudhram
Copy link
Contributor

@vbudhram vbudhram commented Nov 22, 2016

This PR adds some custom deep linking support for Firefox Accounts. Specifically, this allows accounts to launch the FxAContentViewController directly and prefill the form with an email and access_code.

The updated deeplink scheme looks like this.

firefox://?fxa=signin&email=test@email.com&access_code=12345

This update does not change previous deeplinking functionality. If FxA options are not specified, it will work as previously expected.

@vbudhram vbudhram changed the title Bug 1317580 - Add additional deep link support for FxA Bug 1317580 - Add additional deeplink support for FxA Nov 22, 2016
Copy link
Contributor

@farhanpatel farhanpatel left a comment

Thanks for this PR 😃 I've suggested some stylistic changes just to keep things simple

@@ -1968,11 +1968,13 @@ extension BrowserViewController: HomePanelViewControllerDelegate {
}

func homePanelViewControllerDidRequestToCreateAccount(homePanelViewController: HomePanelViewController) {
presentSignInViewController() // TODO UX Right now the flow for sign in and create account is the same
let fxaParams: [String: String] = ["view" : "signup"]

This comment has been minimized.

@farhanpatel

farhanpatel Nov 23, 2016
Contributor

you can skip the [String: String] here .

}

func homePanelViewControllerDidRequestToSignIn(homePanelViewController: HomePanelViewController) {
presentSignInViewController() // TODO UX Right now the flow for sign in and create account is the same
let fxaParams: [String: String] = ["view" : "signin"]

This comment has been minimized.

@farhanpatel

farhanpatel Nov 23, 2016
Contributor

Same as above 😄

"view" : "",
"email" : "",
"code" : ""
]

This comment has been minimized.

@farhanpatel

farhanpatel Nov 23, 2016
Contributor

For something like this it might be simpler to use a struct. You'll be able to use dot notation and better type checking.

@@ -291,8 +304,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func launchFromURL(params: LaunchParams) {
let isPrivate = params.isPrivate ?? false
let fxaParams = params.fxaParams ?? nil

This comment has been minimized.

@farhanpatel

farhanpatel Nov 23, 2016
Contributor

I think it'll be simpler if you just make a new method instead of using the existing LaunchFromURL. That way you dont need to check for a valid fxaParams here.

for item in (components.queryItems ?? []) as [NSURLQueryItem] {
switch item.name {
case "url":
url = item.value
case "private":
isPrivate = NSString(string: item.value ?? "false").boolValue
case "fxa":

This comment has been minimized.

@farhanpatel

farhanpatel Nov 23, 2016
Contributor

I know this loop/switch is already here. But using url.getQuery() will return a dictionary and prevent you from having to loop through results like this.

@@ -614,4 +632,5 @@ extension AppDelegate: MFMailComposeViewControllerDelegate {
struct LaunchParams {
let url: NSURL?
let isPrivate: Bool?
let fxaParams: NSDictionary?

This comment has been minimized.

@farhanpatel

farhanpatel Nov 23, 2016
Contributor

if you create your own LaunchFxAWithURL you can create your own FxAStruct 😄

@vbudhram
Copy link
Contributor Author

@vbudhram vbudhram commented Nov 28, 2016

@farhanpatel A little new to Swift, but I think I got your changes in. Does this look correct? r?

@AaronMT
Copy link
Contributor

@AaronMT AaronMT commented Dec 11, 2016

// Extract optional FxA deep-linking options
let fxaQuery = url.getQuery()
let fxaParams: FxALaunchParams
fxaParams = FxALaunchParams(view: fxaQuery["fxa"], email: fxaQuery["email"], access_code: fxaQuery["access_code"])

This comment has been minimized.

@st3fan

st3fan Dec 13, 2016
Contributor

Will this crash if fxaQuery does not contain any of those fields?

This comment has been minimized.

@st3fan

st3fan Dec 13, 2016
Contributor

(Not sure if looking up an non existent entry will abort/crash or not)

This comment has been minimized.

@vbudhram

vbudhram Dec 13, 2016
Author Contributor

Hey @st3fan, It doesn't appear so. I opened the following deep links in safari and got the following results. These seem to be correct.

  • firefox://?fxa=signin&email=test@email.com

Launches FxiOS, opens the FxA Content View Controller and prefills email.

  • firefox://?fxa=signin

Launches FxiOS, opens the FxA Content View Controller

  • firefox://

Launches FxiOS

This comment has been minimized.

@farhanpatel

farhanpatel Dec 13, 2016
Contributor

Yea it should be fine 👍 You've declared the launch params as optional so it shouldn't crash. They are allowed to be nil

Copy link
Contributor

@farhanpatel farhanpatel left a comment

Almost there! I hope the changes make sense.

return
}
let script = "$('.\(className!)').val('\(value!)');";
webView.evaluateJavaScript(script, completionHandler: { (res, error) -> Void in

This comment has been minimized.

@farhanpatel

farhanpatel Dec 13, 2016
Contributor

You can pass nll to the completionHandler to avoid declaring it.


// Attempt to fill out a field in content view
private func fillField(className: String?, value: String?){
if(className == nil || value == nil){

This comment has been minimized.

@farhanpatel

farhanpatel Dec 13, 2016
Contributor

you can use a guard statement here instead guard let name = className, let val = value else { return }

This comment has been minimized.

@farhanpatel

farhanpatel Dec 13, 2016
Contributor

We usually prefer guard but tbh in this case I think either is fine. Make sure to add a space between the ) and {

@@ -288,6 +299,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

return true
}

func launchFxAFromURL(params: FxALaunchParams) {
let view = params.view ?? nil

This comment has been minimized.

@farhanpatel

farhanpatel Dec 13, 2016
Contributor

A guard statement here would work better guard let view = params.view else { return }

@vbudhram
Copy link
Contributor Author

@vbudhram vbudhram commented Dec 13, 2016

@farhanpatel Thanks for feedback, made changes.

let fxaParams: FxALaunchParams
fxaParams = FxALaunchParams(view: fxaQuery["fxa"], email: fxaQuery["email"], access_code: fxaQuery["access_code"])

if(fxaParams.view != nil){

This comment has been minimized.

@farhanpatel

farhanpatel Dec 13, 2016
Contributor

can you please add spaces between the parans

@farhanpatel farhanpatel merged commit 54c89aa into mozilla-mobile:master Dec 13, 2016
@vbudhram vbudhram deleted the vbudhram:add-fxa-deeplink-support branch Aug 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants