{"id":14,"date":"2011-08-25T22:46:36","date_gmt":"2011-08-25T22:46:36","guid":{"rendered":"http:\/\/www.w3.org\/community\/native-web-apps\/?p=14"},"modified":"2011-10-09T19:37:53","modified_gmt":"2011-10-09T19:37:53","slug":"oauth-and-widgets","status":"publish","type":"post","link":"https:\/\/www.w3.org\/community\/native-web-apps\/2011\/08\/25\/oauth-and-widgets\/","title":{"rendered":"OAuth and Widgets"},"content":{"rendered":"<p>A little while back, I made a quick <a href=\"https:\/\/github.com\/marcoscaceres\/oauth_prototypes\" target=\"_blank\" rel=\"nofollow\">prototype<\/a> showing how widgets could work with OAuth (with Twitter). The problem is that most widget engines don&#8217;t support something like Android&#8217;s <a href=\"http:\/\/developer.android.com\/reference\/android\/webkit\/WebView.html\" target=\"_blank\" rel=\"nofollow\">Web View<\/a>\u00a0and usually can&#8217;t pop up Windows. \u00a0Another issue is that OAuth authentication services usually use <a href=\"https:\/\/developer.mozilla.org\/en\/the_x-frame-options_response_header\" target=\"_blank\" rel=\"nofollow\">X-Frame-Options<\/a>\u00a0header, so that means you can&#8217;t just &#8220;popup&#8221; and iframe.<\/p>\n<p>The goal was just to see what the developer experience was, what is missing, and what complexity was added (I used Chrome with <a href=\"http:\/\/blog.mfabrik.com\/2010\/11\/29\/disabling-cross-domain-security-check-for-ajax-development-in-google-chrome\/\" target=\"_blank\" rel=\"nofollow\">Web Security turned off<\/a> to get it to work like a widget). \u00a0How it works:<\/p>\n<ol>\n<li><a href=\"https:\/\/github.com\/marcoscaceres\/oauth_prototypes\/blob\/master\/index.html\" target=\"_blank\" rel=\"nofollow\">Index.html<\/a> contains\u00a0consumer key, and consumer secret.<\/li>\n<li>I add the widget&#8217;s id as part of the callback url (e.g., http:\/\/example.com\/?widgetid=abc123)<\/li>\n<li>I used\u00a0<a href=\"https:\/\/github.com\/bytespider\/jsOAuth\" target=\"_blank\" rel=\"nofollow\">jsOAuth.js<\/a>\u00a0to do all the magic and get me an authentication token.<\/li>\n<li>I then pop up a window.<\/li>\n<li>I authenticate with twitter.<\/li>\n<li>Twitter then redirects to the callback url.<\/li>\n<li>I &#8216;<a href=\"https:\/\/github.com\/marcoscaceres\/oauth_prototypes\/blob\/master\/success_callback\/index.html\" target=\"_blank\" rel=\"nofollow\">window.opener.postMessage()<\/a>&#8216; the access token\u00a0back to the widget (yes, I know that is bad&#8230; whatever, it&#8217;s a prototype).<\/li>\n<\/ol>\n<p>Costs, complexities, and security issues:<\/p>\n<ul>\n<li>Needed an SSL certificate ($15\/year) +\u00a0static IP address ($3\/month). I don&#8217;t think this cost is too bad.<\/li>\n<li>As the end point of the OAuth flow (the success URL), I assumed I could not use a widget:\/\/.. so I used a real URL. A problem with widget:\/\/ is that it&#8217;s not supposed to be addressable from the outside world (supposed to be opaque).<\/li>\n<li>At the end point, I did a PostMessage() back to the &#8220;widget&#8221; sending the\u00a0authorisation token\u00a0&#8230; \u00a0nasty town, I know. I passed the widget&#8217;s id to twitter over SSL, \u00a0which I used at the end pont to target the cross-doc message.<\/li>\n<\/ul>\n<p>Thinking about it, it could work like an Android URL\u00a0<a href=\"http:\/\/developer.android.com\/guide\/topics\/intents\/intents-filters.html\" target=\"_blank\" rel=\"nofollow\">intent filter<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A little while back, I made a quick prototype showing how widgets could work with OAuth (with Twitter). The problem is that most widget engines don&#8217;t support something like Android&#8217;s Web View\u00a0and usually can&#8217;t pop up Windows. \u00a0Another issue is &hellip; <a href=\"https:\/\/www.w3.org\/community\/native-web-apps\/2011\/08\/25\/oauth-and-widgets\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":233,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[1,6],"tags":[5],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-uncategorized","category-w3cwidgets","tag-w3c-widgets"],"_links":{"self":[{"href":"https:\/\/www.w3.org\/community\/native-web-apps\/wp-json\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.w3.org\/community\/native-web-apps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.w3.org\/community\/native-web-apps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.w3.org\/community\/native-web-apps\/wp-json\/wp\/v2\/users\/233"}],"replies":[{"embeddable":true,"href":"https:\/\/www.w3.org\/community\/native-web-apps\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":2,"href":"https:\/\/www.w3.org\/community\/native-web-apps\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":58,"href":"https:\/\/www.w3.org\/community\/native-web-apps\/wp-json\/wp\/v2\/posts\/14\/revisions\/58"}],"wp:attachment":[{"href":"https:\/\/www.w3.org\/community\/native-web-apps\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.w3.org\/community\/native-web-apps\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.w3.org\/community\/native-web-apps\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}