Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WebActivities - launching an app from Firefox OS browser

725 views
Skip to first unread message

Flaki

unread,
Apr 9, 2013, 5:02:36 PM4/9/13
to
Hello everyone!

I'm building an app that tries to interact with the FourSquare OAuth service to authenticate. Unfortunately, FourSquare requires for the app authorization the user to be redirected to foursquare's own webpage (needs to be opened in a browser), where the user authorizes the app, then it redirects the browser to a pre-set url.

Launching the authorization works like a charm, the "view" webactivity opens up the browser and authentication works as it should. However reopening the app is a hassle (the user must be presented a page after redirect, that instructs him to reopen the app and refresh/sync to receive his auth key).

Browsing the WebActivity docs (which are quite scarce, at most) I found out there is an "open" action, could probably this be used to launch the app from the browser? I'm thinking something not at all unlike android's intents... Unfortunately I didn't find any pointers (or any documentation) for the action.

Thanks in advance!
Flaki

Paul Theriault

unread,
Apr 9, 2013, 10:03:28 PM4/9/13
to Flaki, dev...@lists.mozilla.org
See https://developer.mozilla.org/en-US/docs/WebAPI/Web_Activities

I think you want "view".

The docs say:

type: "url"
url: {
required: true,
regexp: /^https?:.{1,16384}$/
}

Which means something lihe this:

new MozActivity({
"name":"view",
"data":
{
"type":"url",
"url":"http://mozilla.org"
}
});



On Apr 10, 2013, at 7:02 AM, Flaki wrote:

> Hello everyone!
>
> I'm building an app that tries to interact with the FourSquare OAuth service to authenticate. Unfortunately, FourSquare requires for the app authorization the user to be redirected to foursquare's own webpage (needs to be opened in a browser), where the user authorizes the app, then it redirects the browser to a pre-set url.
>
> Launching the authorization works like a charm, the "view" webactivity opens up the browser and authentication works as it should. However reopening the app is a hassle (the user must be presented a page after redirect, that instructs him to reopen the app and refresh/sync to receive his auth key).
>
> Browsing the WebActivity docs (which are quite scarce, at most)

A spiteful and malicious falsehood! Ok we are working on it. ;) Follow the status here:

https://developer.mozilla.org/en-US/docs/WebAPI/Doc_status

> I found out there is an "open" action, could probably this be used to launch the app from the browser? I'm thinking something not at all unlike android's intents... Unfortunately I didn't find any pointers (or any documentation) for the action.
>
> Thanks in advance!
> Flaki
> _______________________________________________
> dev-b2g mailing list
> dev...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-b2g

Flaki

unread,
Apr 9, 2013, 10:41:51 PM4/9/13
to
Thanks for the reply, but I see that I forgot to mention: this is an installed /packaged/ app, not a hosted one, so launching it via a URL is not an option.

Paul Theriault

unread,
Apr 10, 2013, 12:38:41 AM4/10/13
to Flaki, dev...@lists.mozilla.org
Ah ok, sorry I misunderstood. Can you use a popup window in your app instead of switching to the browser proper? I.E. Are you aware that there is a difference between calling window.open(...,'_blank') and just window.open() in Firefox OS? In Firefox OS Apps, calls to window.open(...,'_blank') get translated into web activity which opens in the browser app. Calls to window.open() create a system provided window which overlays the app, instead of opening the browser app proper. I believe the main purpose of this feature is to support oAuth style flows. Closing this window then shows the app again. Maybe this suits your purposes?

If not, then I am not sure. In theory you could have your app handle a web activity, and start that activity from a web page. But there is no way to guarantee that your app will be the one which handles the web activity (if more than one app is registered as a web activity handler, the user if prompted to choose which app they want to open)

- Paul

On Apr 10, 2013, at 12:41 PM, Flaki wrote:

> Thanks for the reply, but I see that I forgot to mention: this is an installed /packaged/ app, not a hosted one, so launching it via a URL is not an option.

Kevin Grandon

unread,
Apr 10, 2013, 1:14:50 AM4/10/13
to Paul Theriault, Flaki, dev...@lists.mozilla.org
I'm not sure a web activity is the implementation you're looking for here.

Dealing with Oauth flows is a bit tricky right now due to how the system app intercepts window.open/window.close. The best thing to do is to look at our Facebook implementation inside of the communications app. I don't remember all of the details, but it works something like:

1 - Create an Iframe to a local HTML file which redirects to the Oauth provider.
2 - When the Oauth provider redirects back to your iframe, use postMessage to notify the parent.
3 - The parent window can then close the iframe.

Best,
Kevin Grandon

Flaki

unread,
Apr 10, 2013, 6:34:18 AM4/10/13
to
Thank you for the pointers! I actually tried using iframes first, but turns out the auth dialog prohibits its embedding in iframes via extra headers, so I went on with the "view" activity approach.

It is funny, but using window.open never occurred to me - i tried now and it seems to be working like a charm. Thanks!

Flaki

unread,
Apr 9, 2013, 10:34:19 PM4/9/13
to Paul Theriault, dev...@lists.mozilla.org
Thanks for the reply, but I see that I forgot to mention: this is an
installed /packaged/ app, not a hosted one, so launching it via a URL is
not an option.


2013/4/10 Paul Theriault <pther...@mozilla.com>

> See https://developer.mozilla.org/en-US/docs/WebAPI/Web_Activities
>
> I think you want "view".
>
> The docs say:
>
> type: "url"
> url: {
> required: true,
> regexp: /^https?:.{1,16384}$/
> }
>
> Which means something lihe this:
>
> new MozActivity({
> "name":"view",
> "data":
> {
> "type":"url",
> "url":"http://mozilla.org"
> }
> });
>
>
>
> On Apr 10, 2013, at 7:02 AM, Flaki wrote:
>
> > Hello everyone!
> >
> > I'm building an app that tries to interact with the FourSquare OAuth
> service to authenticate. Unfortunately, FourSquare requires for the app
> authorization the user to be redirected to foursquare's own webpage (needs
> to be opened in a browser), where the user authorizes the app, then it
> redirects the browser to a pre-set url.
> >
> > Launching the authorization works like a charm, the "view" webactivity
> opens up the browser and authentication works as it should. However
> reopening the app is a hassle (the user must be presented a page after
> redirect, that instructs him to reopen the app and refresh/sync to receive
> his auth key).
> >
> > Browsing the WebActivity docs (which are quite scarce, at most)
>
> A spiteful and malicious falsehood! Ok we are working on it. ;) Follow
> the status here:
>
> https://developer.mozilla.org/en-US/docs/WebAPI/Doc_status
>
> > I found out there is an "open" action, could probably this be used to
> launch the app from the browser? I'm thinking something not at all unlike
> android's intents... Unfortunately I didn't find any pointers (or any
> documentation) for the action.
> >
> > Thanks in advance!
> > Flaki

asa...@gmail.com

unread,
Feb 22, 2014, 12:16:47 PM2/22/14
to
On Wednesday, April 10, 2013 12:34:18 PM UTC+2, Flaki wrote:
> Thank you for the pointers! I actually tried using iframes first, but turns out the auth dialog prohibits its embedding in iframes via extra headers, so I went on with the "view" activity approach.
>
>
>
> It is funny, but using window.open never occurred to me - i tried now and it seems to be working like a charm. Thanks!

How did it go? What is the "view" activity approach?

I want to implement the Faceook Login witch requires oAuth!

AJ ONeal

unread,
Oct 1, 2014, 12:58:49 AM10/1/14
to mozilla...@lists.mozilla.org
I understand conceptually how to perform OAuth2 via an iFrame and I've done it before. What I can't figure out is how to redirect back to the app.

Can someone give a working example or a link to a *simple* github repo?

I imagine the flow to be something like this:

w = window.open("/oauth-open.html", "oauth-dialog");
window.finishOauth(access_token) {
window.access_token = access_token;
w.close();
}

In my oauth-open.html I would put a link such as

http://example.com/oauth/connect?redirect_uri={{what-do-i-put-here???/oauth-close.html}}

And then in my oauth-close.html in my app I would read the access_token from the query parameter and pass it back to my main app with window.opener.finishOauth(access_token)

But I'm missing what the redirect_uri should be and I'm not clear on what needs to be in the manifest.webapp to allow all of this to happen.

Please fill in some of the gaps for me. Thanks. :-D

Jason Weathersby

unread,
Oct 1, 2014, 1:18:44 AM10/1/14
to AJ ONeal, mozilla...@lists.mozilla.org
I am not sure this is the best way but I found similar code somewhere but do not remember where :)
I got this to work with Facebook using:
pickLogin.onclick = function () {
var ruri = "https://www.facebook.com/dialog/oauth?client_id={myid}&redirect_uri=https://www.facebook.com/connect/login_success.html";
window.open(ruri);

};

Then using the redirect manifest field

"redirects": [
{"from": "https://www.facebook.com/connect/login_success.html",
"to": "/redirects/auth.html"}
]

Where auth.html under my redirects can query for the the token.


--
Jason Weathersby


----- Original Message -----
From: "AJ ONeal" <cool...@gmail.com>
To: mozilla...@lists.mozilla.org
Sent: Tuesday, September 30, 2014 9:58:38 PM
Subject: Re: [b2g] WebActivities - launching an app from Firefox OS browser

Jason Weathersby

unread,
Oct 1, 2014, 1:45:27 AM10/1/14
to AJ ONeal, mozilla...@lists.mozilla.org
You may also want to look at:
https://github.com/mozilla-b2g/gaia/tree/master/dev_apps
specifically contacts-ds-provider1 and contacts-ds-provider2
0 new messages