<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cory Forsyth on Medium]]></title>
        <description><![CDATA[Stories by Cory Forsyth on Medium]]></description>
        <link>https://medium.com/@bantic?source=rss-36f8e59ad65f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*af0F_MCaf89OT_csrTWsnQ.jpeg</url>
            <title>Stories by Cory Forsyth on Medium</title>
            <link>https://medium.com/@bantic?source=rss-36f8e59ad65f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 03:57:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bantic/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Ember Table 2.0 Release]]></title>
            <link>https://medium.com/@bantic/ember-table-2-0-release-5b91903f3e34?source=rss-36f8e59ad65f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b91903f3e34</guid>
            <category><![CDATA[table]]></category>
            <category><![CDATA[datatables]]></category>
            <category><![CDATA[ember]]></category>
            <dc:creator><![CDATA[Cory Forsyth]]></dc:creator>
            <pubDate>Mon, 12 Aug 2019 17:52:23 GMT</pubDate>
            <atom:updated>2019-08-12T17:52:23.145Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m excited to announce the release of Ember Table 2.0. This release is the culmination of more than 18 months of effort across several Addepar developers and <a href="https://github.com/Addepar/ember-table/graphs/contributors?from=2017-05-14&amp;to=2019-07-30&amp;type=c">external contributors</a>. This release represents a ground-up re-implementation of Ember Table with a new, modern, and future-compatible API. At Addepar, the new Ember Table 2.0 (“ET2”) brings even better performance on large tables and its enhanced flexibility is a better fit for the advanced use cases that Addepar clients have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-rmCR966iDPC_PCgI85Mkg.png" /><figcaption>Ember Table in use in the Ember Inspector extension</figcaption></figure><p>Over the past year we’ve adopted ET2 into much of Addepar’s product, and in an upcoming release we will have completed our migration away from the legacy version. That milestone, and the corresponding stability requirements, merit an official major release.</p><p><em>Since this release diverges significantly from Ember Table 1.0, we renamed the original version of the library and repo to “ember-table-legacy” to make it easy for legacy codebases to continue using the older version.</em></p><p>If you’ve been waiting to try ET2, now is a great time. It’s a powerful and flexible data table library designed to be approachable yet full of features to accommodate complex needs, such as:</p><ul><li>fixed headers, footers, and columns</li><li>row selection and sorting</li><li>tree tables with group collapsing</li><li>column resizing and reordering</li><li>nested subcolumns (an all-new feature in ET2 that supports complex table headers, for example to create pivot tables)</li><li>ability to render thousands of rows performantly via occlusion rendering (leveraging <a href="https://github.com/html-next/vertical-collection">vertical-collection</a>)</li><li>compatibility with Ember versions 1.13 through 3.10, with a progressively improved API</li><li>exported test object for testing tables in your app</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nFjP_p-DSe1guxH6IuNctw.gif" /><figcaption>Ember Table supports sorting, column reordering, nested data, and more</figcaption></figure><p>Additionally, significant effort went into revamping ET2 documentation. The docs use <a href="https://github.com/ember-learn/ember-cli-addon-docs">ember-cli-addon-docs</a> so that they are searchable and versioned, with expanded sections and interactive demos.</p><p>To start using the new ET2, add `ember-table@^2` to your Ember app’s dependencies, then read <a href="https://opensource.addepar.com/ember-table/docs">the documentation</a>.</p><p>Questions or comments? File an issue on GitHub or join us in the <em>#topic-tables</em> channel in the <a href="https://discordapp.com/invite/zT3asNS">Ember Community Discord</a>.</p><p>Interested in working with us at Addepar? Visit <a href="https://addepar.com/careers/">addepar.com/careers</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b91903f3e34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add a “Quit” button to Chrome; or, a Cruel April Fools prank to play on Chrome-using coworkers]]></title>
            <link>https://medium.com/@bantic/add-a-quit-button-to-chrome-or-a-cruel-april-fools-prank-to-play-on-chrome-using-coworkers-21320e7d7fba?source=rss-36f8e59ad65f------2</link>
            <guid isPermaLink="false">https://medium.com/p/21320e7d7fba</guid>
            <category><![CDATA[pranks]]></category>
            <category><![CDATA[april-fools]]></category>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[browsers]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Cory Forsyth]]></dc:creator>
            <pubDate>Thu, 28 Mar 2019 19:07:15 GMT</pubDate>
            <atom:updated>2019-03-28T19:07:15.147Z</atom:updated>
            <content:encoded><![CDATA[<p>If you use Chrome, you may be aware of all of its special pages. If you aren’t, these are worth taking a moment to explore — there are many interesting details about Chrome internals that you can find on these pages. To view the full list of them, type <strong>chrome://chrome-urls/ </strong>into Chrome’s address bar.</p><p>So what is the prank? First, find a coworker who a) uses Chrome and b) has some bookmarks on their Bookmarks Bar. The Bookmarks Bar is a strip of real estate directly below the address bar, where it is possible to have single-clickable icons that take you directly to the bookmarked link in question. They look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aVaIaTKBag-U4U8707J46w.png" /><figcaption>The Chrome bookmarks bar, with several bookmarks</figcaption></figure><p>The bar may be hidden; if so, it can be revealed by choosing the menu option at View-&gt;Always Show Bookmarks Bar.</p><p>So what is the prank? If you look down the list of the chrome special URLs, there’s a section of unlinked URLs at the end under a <strong>Debug</strong> heading. They aren’t linked because clicking them does potentially bad things to the browser.</p><p>To play a trick on a coworker, control-click one of their commonly-used bookmarks, edit it, and change the URL to one of those debug chrome URLs. You have your pick of several, depending on how evil you want to be. Here they are, in increasing order of devilishness:</p><ul><li><strong>chrome://crash/</strong> — This will crash the current tab only. Fairly benign.</li><li><strong>chrome://restart/</strong>—Restarts the entire browser, but it will come back with all the same tabs that were open. This is more of a wtf-inducing prank.</li><li><strong>chrome://quit/</strong> — This is getting into nasty territory. Upon clicking this bookmark, Chrome will immediately go <em>poof</em>. When it restarts all tabs will be gone. A savvy Chrome user will likely know how to restore them. Either way, best to stand clear if you prank someone with this option.</li><li><strong>chrome://inducebrowsercrashforrealz/ </strong>—Yes, that is a real URL. It crashes the browser <em>hard</em>. Spinning wheel, force-quit sort of situation. In one way it’s more of a nasty surprise, but in another it’s a kinder option than chrome://quit, because when Chrome is restarted it will offer the “Chrome shut down incorrectly before, want to restore tabs?” option. It just might be a while before it finishes crashing and gives you that chance.</li></ul><p>And if none of these is your idea of a good time (if they are, we may not able to be friends), another idea is to make your own spiffy “Quit” button for <em>your </em>Chrome. Add a bookmark to <strong>chrome://quit</strong> as described above, and you have a fun clickable icon on your bookmarks bar that you can use to quit. In case typing command-Q has lost its luster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ry8MbSAt4uPjY71uJEzmA.jpeg" /><figcaption>Add a Quit button to your Chrome!</figcaption></figure><p><em>I take no responsibility for adverse consequences in the case that you actually do edit your coworkers’ bookmarks!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21320e7d7fba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I freed 15GB by deleting old node_modules directories (and you can, too)]]></title>
            <link>https://medium.com/@bantic/i-freed-15gb-by-deleting-old-node-modules-directories-and-you-can-too-7baeadd08a39?source=rss-36f8e59ad65f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7baeadd08a39</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[unix]]></category>
            <dc:creator><![CDATA[Cory Forsyth]]></dc:creator>
            <pubDate>Wed, 28 Jun 2017 21:46:18 GMT</pubDate>
            <atom:updated>2017-06-28T21:51:23.829Z</atom:updated>
            <content:encoded><![CDATA[<p>npm installs node modules to a local node_modules directory for every project you have, and, if you’re like me, over time you’ll accumulate a lot of crusty old node_modules dirs. They can easily take up 10s to 100s of megabytes. By deleting these old directories you can free up several gigabytes of disk space. I did a sweep of my own recently and freed over 15GB.</p><p>It’s important to keep in mind that without a good lock file an npm install is not deterministic, so some module directories that you delete will not reinstall the same way. This is especially true if your package.json includes version ranges, because upon reinstall npm may find newer versions of your modules that satisfy the requested range. So, buyer beware. Please <strong>make sure you have backed up and that you know what you are doing</strong> before blindly copying and pasting the commands here, or you could delete much more than you intended.</p><p>Also note: <strong>This technique won’t work if you have filepaths with spaces in them</strong>, and could in fact cause some you to delete some unintended files. (There’s a section at the end that explains why.) Only the commands listed below with “rm” in them can cause harm, so you can still follow along safely until that point.</p><p>When I did this sweep I wasn’t too concerned about reinstalls of node_modules being different because many of the directories I was clearing out had been installed with older versions of node. They likely were out of date already. I had a need to free up some disk space quickly, and decided to let future me deal with reinstallation issues.</p><p>On macOS, use the find tool to find all directories named node_modules. The -prune flag instructions find not to descend after it finds a match. Without it you’d find hundreds of nested node_modules directories.</p><pre>find <strong>~/work</strong> -type d -name &#39;node_modules&#39; -prune</pre><p>Use du to get an idea for how much disk space these directories take up. Pass the “h” and “s” flags to displays size info in human-readable form (mb, gb, …) totals per directory instead of each file within that directory:</p><pre>find <strong>~/work</strong> -type d -name &#39;node_modules&#39; -prune | xargs du -sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EApclV1qdSCHUQ5LZVDwdw.png" /></figure><p>Wow. Three directories and nearly a gigabyte (900MB) in potential savings already. (Note: If find found any filepaths with spaces in them, you will likely see errors here from du, and that’s an indication that you should not use the commands below because they may delete more than you intended.)</p><p>The GNU sort command can sort by the human-readable sizes that du outputs if you pass it the “h” flag. On macOS you should <strong>use </strong><strong>brew to install </strong><strong>coreutils</strong>, which will install gsort. It is the same as the built-in sort except that it recognizes the “h” flag. Use the “r” flag to reverse the output so largest sizes are listed first:</p><pre>find <strong>~/work</strong> -type d -name &#39;node_modules&#39; -prune | xargs du -sh \<br>  | gsort -rh</pre><p>This gives a list of the worst offenders and you can selectively delete them at your leisure.</p><p>I opted for the shot-gun approach, though, piping each line to rm -r to do the deletion in a single unix command. If you are looking for a single command to run, that deletes all your node_modules directories (within some parent dir), this is it. <strong>Again, do not use this if you had any issues before, or if you have filepaths with spaces (or, in general, if you don’t understand what you are doing):</strong></p><pre>find <strong>~/work</strong> -type d -name &#39;node_modules&#39; -prune | xargs rm -r</pre><p>Another option is to continue to utilize du and gsort and select only a few of the heaviest directories to pipe to our rm -r. To do so, thread through calls to the head command (to limit to the top X results) and the cut command, which is necessary to remove the size information that du outputs. du adds 6 characters to the beginning of each line, so cut those using cut -c 6- :</p><pre>find ~/work -type d -name &#39;node_modules&#39; -prune | xargs du -sh \<br>  | gsort -rh | head -10 | cut -c 6- | xargs rm -r</pre><p>And there you go. That one-liner will delete the 10 heaviest (by file size) ‘node_modules’ directories anywhere within the ~/work parent directory.</p><h4>Alternative Approaches</h4><p>You could use the mtime or size flags with find to limit by modified-time or file-size.</p><p>To learn more about find, I recommend this <a href="http://mywiki.wooledge.org/UsingFind">excellent guide</a>. It’s a poorly understood but very powerful tool.</p><h4>A note on spaces in filepaths</h4><p>I warn above to be extra careful using these commands if you have spaces in your filepaths. This is because when a string with a space piped to xargs , it will operate as though you gave it two commands instead. For example if you have a filepath “/Users/me/abc def” that is piped to xargs rm -r, it is as though you did rm -r /Users/me/abc def, and rm will attempt to remove /Users/me/abc <em>and</em> def instead of the single argument “/Users/me/abc def”.</p><p>The find command accepts the print0 flag, which causes it to print results using a null terminator (instead of a newline), and xargs has a correlated -0 flag that causes it to assume incoming arguments are separated by null characters. These flags go well together to fix the issues described above. However, in the one-liner above you’ll notice that output is piped into xargs twice, once from print and then again later from cut. The output from cut will <em>again</em> use spaces and newlines, so the second xargs, xargs rm -r will still suffer from the issue described.</p><p>There is a workaround, for the intrepid, which is to use null-terminators all the way through. This is possible if you did install coreutils, as mentioned above; it provides g-prefixed versions of the commands used, and those will each accept the “-z” flag to output nulls instead of newlines. And you need to use tr to translate the newlines that du prints. Hat tip to @mixonic for his assistance on this monstrosity:</p><pre>find ~/work -type d -name &#39;node_modules&#39; -prune -print0 | \<br>  xargs -0 du -sh | \<br>  tr &#39;\n&#39; &#39;\0&#39; | \<br>  gsort -zrh | ghead -z -n 10 | gcut -z -c 6- | xargs -0 rm -r</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7baeadd08a39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Mobiledoc-Kit to build an auto-linking text editor]]></title>
            <link>https://medium.com/@bantic/use-mobiledoc-kit-to-build-an-auto-linking-text-editor-771bdb0b8709?source=rss-36f8e59ad65f------2</link>
            <guid isPermaLink="false">https://medium.com/p/771bdb0b8709</guid>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[mobiledoc]]></category>
            <dc:creator><![CDATA[Cory Forsyth]]></dc:creator>
            <pubDate>Wed, 21 Jun 2017 16:59:10 GMT</pubDate>
            <atom:updated>2017-06-21T16:59:10.787Z</atom:updated>
            <content:encoded><![CDATA[<p>Mobiledoc-Kit is a library for building WYSIWYG editors supporting rich content via cards. It was developed by our team at <a href="https://www.201-created.com/">201 Created</a> for the fine folks at <a href="https://www.bustle.com/labs">Bustle</a>. To learn more about it, visit <a href="https://github.com/bustle/mobiledoc-kit">Mobiledoc-Kit</a> on github or <a href="/service/mailto:hello@201-created.com?Mobiledoc-Kit">say hello</a> to our team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*5_rIR-SIWP50fFKq6pfQ3w.png" /></figure><p>In this post I’ll showcase one of the useful editing hooks that the Mobiledoc API offers: onTextInput. I’ll create a text editor that automatically links URLs as you type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*FXNWbMdHrlsAn9gwUs4hOA.gif" /><figcaption>The finished product: A Mobiledoc editor that aut0-links as you type.</figcaption></figure><p>onTextInput is a hook that you can configure on an instance of a Mobiledoc Editor. It requires 3 things: a name, a property to match on which can either be a regular expression(match) or a string (text), and a callback function (run)that Mobiledoc will invoke when the user types some matching text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aX9dCim8kgCH6hZxXivgnw.jpeg" /><figcaption>The docs for `onTextInput`. = <a href="http://bustle.github.io/mobiledoc-kit/demo/docs/Editor.html#onTextInput">available online</a>.</figcaption></figure><p>The callback function, run, gets called with 2 arguments: an instance of the editor and an array that contains the matched segment(s). For instance, here’s how you would configure an editor that quacks every time the word “duck” is typed. (Note that in this and future code snippets I assume an instance of an editor is already available in the editor variable.)</p><pre>editor.onTextInput({<br>  name: &#39;quacker&#39;,<br>  text: &#39;duck&#39;,<br>  run(editor, matches) { alert(&#39;Quack!&#39;); }<br>});</pre><p>Not very useful, but helps illustrate the point. You can try it live <a href="https://codepen.io/bantic/pen/zzwzdx">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*aN5sQ3fY_-UGFTx42j2qPw.gif" /></figure><p>Here is a regex that will match some text that starts (after a word boundary) with http or https and ends with a space:</p><pre>/\b(https?:\/\/[^\s]+)\s$/</pre><p>Take it for a whirl on this <a href="http://regexr.com/3g70f">regex explorer</a> if you’d like to confirm for yourself that it’ll match.</p><p>Here’s how we would register a text input handler that will respond when the user types such a URL:</p><pre>editor.onTextInput({<br>  name: &#39;linkify&#39;,<br>  match: /\b(https?:\/\/[^\s]+)\s$/,<br>  run(editor, matches) {<br>    // linkify the matched url<br>  }<br>});</pre><p>If you add a log statement inside that run callback you should see that it fires at the expected time.</p><p>In order to link up the text there are few more Mobiledoc concepts to learn:</p><ul><li>The Mobiledoc Range. A Range is a logical section of a Mobiledoc document, comprised of a starting Position property called head and an ending Position property called tail. In Mobiledoc a Range can be collapsed, in which case its head will be the same as its tail, or expanded. A Mobiledoc editor instance can have 0 or 1 currently active range at any given time, and it can be accessed through the range property: editor.range.</li><li>The Mobiledoc Position primitive is a zero-width spot in a Mobiledoc document, identified by which Section of the document it is in, as well as its offset within that section. A Position can be thought of as lying between two characters in a given section (similar to the native text cursor).</li></ul><p>The Mobiledoc documentation includes more information on the methods that <a href="http://bustle.github.io/mobiledoc-kit/demo/docs/Range.html">Mobiledoc.Range</a> provides. For this tutorial we’ll use the move method, which will shift a range to the left or right, and extend, which changes the width of the range by moving its head or tail (depending on the direction of extension).</p><p>In order to modify the existing document, Mobiledoc exposes an editor.run method that you can use to apply a set of mutations. Pass a function toeditor.run that it will then call with an instance of a PostEditor — a PostEditor exposes methods that can be used to modify the document, e.g. inserting or deleting text, and modifying the markup applied to a given range. The method we will use in this tutorial is addMarkupToRange, which introduces another Mobiledoc concept, Markup. A Markup is a decoration that can be applied to text, such as to make it <strong>strong</strong>, <em>emphasized</em>, or, in our case, to make it a link.</p><p>To create a markup, use the builder that the editor exposes. For instance, to create a markup that is a link to this post, do:</p><pre>let linkMarkup = editor.builder.createMarkup(<br>  &#39;a&#39;, {href: &#39;<a href="https://medium.com/p/771bdb0b8709">https://medium.com/p/771bdb0b8709</a>&#39;}<br>);</pre><p>The last thing to know is that the editor exposes a method selectRange that can be used to set the cursor position.</p><p>We can now start putting these pieces together to create an editor that auto-links URLs. Inside the run callback we will need to:</p><ol><li>create a logical Range that includes only the URL</li><li>create a markup that is a link to that URL</li><li>use Editor.run and the PostEditor to apply that markup to the range</li><li>Restore the cursor position</li></ol><p>Here’s a code snippet that puts the pieces together:</p><pre>editor.onTextInput({<br>  name: &#39;linkify&#39;,<br>  match: /\b(https?:\/\/[^\s]+)\s$/,<br>  run(editor, matches) {<br>    let url = matches[0];</pre><pre>    // the editor&#39;s current range is the cursor position, 1<br>    // character after the URL (to account for the space).<br>    // Keep a reference to this range so that it can be restored later<br>    let currentRange = editor.range;</pre><pre>    // 1. Create a logical range containing the URL.<br>    // Move the range 1 space backward (to skip over the space), and<br>    // then extend it backward the length of the URL:<br>    let linkRange = currentRange.move(-1).extend(-url.length);</pre><pre>    // 2. Create the markup<br>    let linkMarkup = editor.builder.createMarkup(&#39;a&#39;, {href: url});</pre><pre>    // 3. apply the markup to the range<br>    editor.run((postEditor) =&gt; {<br>      postEditor.addMarkupToRange(linkRange, linkMarkup);<br>    });</pre><pre>    // 4. restore the cursor position<br>    editor.selectRange(currentRange);<br>  }<br>});</pre><p>And here is an embedded code pen. Feel free to click in to type and try it out for yourself!</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodepen.io%2Fbantic%2Fpen%2FWOjjEO%3Feditors%3D0010&amp;src=https%3A%2F%2Fcodepen.io%2Fbantic%2Fembed%2Fpreview%2FWOjjEO%3Fheight%3D600%26slug-hash%3DWOjjEO%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed64c8b69750a0a54362eab73e3e8ceb/href">https://medium.com/media/ed64c8b69750a0a54362eab73e3e8ceb/href</a></iframe><p>I hope this gives you a sense of the power of Mobiledoc, as well as whets your appetite to give it a try. In this tutorial I’ve elided some setup steps. The way you’ll need to import Mobiledoc for use in your application will depend on your build setup and other tooling. Mobiledoc ships in several flavors including global, AMD, commonjs, and ES2015+, as well as has wrappers available for frameworks including React, Ember and others. Find out more at the <a href="https://github.com/bustle/mobiledoc-kit">github repo</a>. In these Codepens I’ve used <a href="https://unpkg.com/">unpkg</a> to include the global JS as well as the CSS.</p><p>It’s obvious but also worth mentioning that the onTextInput hook doesn’t necessarily have to modify the editor’s document, it can instead be used as a way to allow the rest of the editing environment to react to the text that is being typed. For example, you could have an editor that has a side panel (not managed by Mobiledoc) that would automatically look up definitions of words as the user typed them. Here’s a <a href="https://codepen.io/bantic/pen/PjmKLY?editors=0010">sillier demo</a> that changes the page’s background color in reaction to what the user types:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*9HbnuHGwHYIFadxUNw9wWA.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=771bdb0b8709" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Torii Vulnerability Disclosure]]></title>
            <link>https://medium.com/@bantic/torii-vulnerability-disclosure-dd98b6d88ec3?source=rss-36f8e59ad65f------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd98b6d88ec3</guid>
            <category><![CDATA[oauth]]></category>
            <category><![CDATA[torii]]></category>
            <category><![CDATA[ember]]></category>
            <dc:creator><![CDATA[Cory Forsyth]]></dc:creator>
            <pubDate>Wed, 24 May 2017 14:30:29 GMT</pubDate>
            <atom:updated>2017-05-25T18:40:59.987Z</atom:updated>
            <content:encoded><![CDATA[<p>Security researcher <a href="https://tritarget.org/">Devin Weaver</a> recently disclosed to us at 201 Created that <a href="https://github.com/vestorly/torii">Torii</a>, the Auth Ember.js addon that we maintain, has a potential security vulnerability. The vulnerability affects all versions of Torii before 0.9.1 and can allow third parties to obtain the provided code and any other parameters passed in the query string of a redirect callback URL from an OAuth provider.</p><p><strong>Update May 25 2017</strong>: Edited to suggest using v0.9.5 of Torii.</p><h4>Is Your App Affected?</h4><p>Your app is only affected if <em>all</em> of the following are true:</p><ul><li>It uses any Torii OAuth Provider that uses a web redirection flow (such as the OAuth 2.0 <a href="https://tools.ietf.org/html/rfc6749#section-4.1">Authorization Code Grant</a> flow) that passes sensitive parameters in the the redirect URL query string. This includes all of the built-in OAuth 2 code and OAuth 1 providers. Any Torii provider that requires configuring a redirectUri is potentially affected.</li><li>It uses a redirectUri that loads your Ember app. This is the Torii default.</li><li>Your Ember app loads third-party assets (scripts, images or stylesheets).</li></ul><h4>Your App Is Not Affected If</h4><p>Your app is not affected if any of the following are true:</p><ul><li>It doesn’t use any Torii OAuth providers.</li><li>It uses the facebook-connect provider.</li><li>It uses the google-oauth2-bearer provider or another provider that passes sensitive data through the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/hash">URL hash</a> rather than the query string.</li><li>Your Ember app doesn’t load any third-party assets.</li><li>You have configured a redirectUri with the OAuth provider that loads a page outside of your Ember app (and that page doesn’t load any third-party assets).</li></ul><h4>What To Do If Your App is Affected</h4><p>Take the following steps:</p><ul><li>Upgrade Torii to version ^0.9.5</li><li>Change the registered redirectUri at the OAuth provider(s) that you use to be: &lt;YOUR-APP-BASE-URL&gt;/torii/redirect.html</li><li>Ensure your Ember app’s Torii configuration specifies this new URL for itsredirectUri. Torii 0.9.5 uses this as its default.</li></ul><p>If you are unable to upgrade Torii you can host your own static redirect page by copying the HTML and JavaScript from the Torii addon’s <a href="https://github.com/Vestorly/torii/blob/master/public/redirect.html">public/redirect.html</a>.</p><h4>Explanation of Vulnerability</h4><p>For redirect-based OAuth flows, Torii opens a popup window (or iframe) from the app’s main window. The popup window is loaded with the URL for an OAuth provider (e.g. “https://accounts.google.com/o/oauth2/auth”). After the user has logged in with the provider and clicked to allow access, the OAuth provider will redirect the window to your registered redirectUri with a codeparameter appended in the query string.</p><p>If the page that it redirects to loads any third-party assets, the browser will fetch those assets and send the current URL in the HTTP referer header, including the sensitive code parameter in the query-string, effectively transmitting this parameter to the third-party server.</p><h4>Impact of Vulnerability</h4><p>The code parameter from an OAuth provider can be used by an attacker to replay an OAuth request. Possession of the code by itself does not grant access to a user’s data at the OAuth provider (unlike an OAuth access_token). In order to obtain an access token, your backend must communicate securely, server-to-server, using the obtained code as well as the OAuth provider-issued client id and secret. As a result, possession of the code by itself is usually not sufficient for an attacker to obtain an access token, but by replaying an OAuth request flow, an attacker could trick your backend into associating their OAuth Provider account with a victim’s account. The impact of leaking the code parameter is mitigated somewhat by the fact that the only potential third parties that could view the code are third parties that you have already implicitly trusted (somewhat) by adding their scripts/images/css to your app.</p><p>For more detail on relevant security considerations see <a href="https://tools.ietf.org/html/rfc6819#section-4.4">section 4.4</a> on the authorization code in RFC 6819, “OAuth 2.0 Threat Model and Security Considerations”.</p><p>For additional context on OAuth see this guide to the <a href="https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2#grant-type-authorization-code">OAuth 2.0 authorization code grant</a> flow, Aaron Parecki’s <a href="https://aaronparecki.com/oauth-2-simplified/">OAuth 2 Simplified</a>, and a post I wrote titled <a href="https://medium.com/@bantic/some-surprising-things-about-oauth-2-0-7a328f1b4952">Some Surprising Things About OAuth 2.0</a>. A description of this particular type of OAuth vulnerability is described in more detail <a href="https://homakov.blogspot.com/2012/07/saferweb-most-common-oauth2.html">here</a>.</p><h4>Responsible Disclosure</h4><p>We appreciate the efforts of Devin Weaver to responsibly disclose this vulnerability to us and work with us to put together an effective mitigation strategy. As a result of this experience we have also updated Torii’s readme section to have a dedicated Security section. If you discover a vulnerability in Torii please let us know by emailing <a href="/service/mailto:security@201-created.com">security@201-created.com</a>. You can encrypt the message with our <a href="https://keybase.io/bantic/pgp_keys.asc">public key</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd98b6d88ec3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hand-coding a color wheel with canvas]]></title>
            <link>https://medium.com/@bantic/hand-coding-a-color-wheel-with-canvas-78256c9d7d43?source=rss-36f8e59ad65f------2</link>
            <guid isPermaLink="false">https://medium.com/p/78256c9d7d43</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[rgb]]></category>
            <category><![CDATA[hsv]]></category>
            <category><![CDATA[canvas]]></category>
            <dc:creator><![CDATA[Cory Forsyth]]></dc:creator>
            <pubDate>Sun, 12 Feb 2017 17:09:01 GMT</pubDate>
            <atom:updated>2017-02-12T17:18:04.225Z</atom:updated>
            <content:encoded><![CDATA[<p>The other day I found myself staring my monitor as my Mac disgracefully spun the beachball of death at me, and in addition to wondering what I had done to deserve this fate I started to wonder how one might describe the algorithm that distributes those colors with code. When my Mac finally came back to life I decided to play around a little and see if I could do it. This post is the result of that exploration.</p><p>By the end of this post I’ll have shown you how to use canvas to make a color wheel on the web, similar to Apple’s circular color picker:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/228/1*2WBfYvHlY-IMMeQqPi6Jqw.png" /><figcaption>Our goal: Render a color wheel like Apple’s HSL color picker picture here</figcaption></figure><p>When faced with any new programming challenge, it’s critical to break it down into smaller steps that are more approachable—by building those and layering them atop each other it’s possible to achieve our more ambitious overall goal. In the case of this post the steps will be:</p><ul><li>Figure out how to just draw <em>something</em> (in this post it will be a red square)</li><li>Refine our drawing so that we restrict the pixels to a <em>circle</em></li><li>Find out hwo to map colors to specific angles around the circle</li><li>Voila: a color wheel!</li></ul><p>I’ve identified the HTML5 &lt;canvas&gt; element as our first building block. We’ll eventually use it to draw the entire color wheel, but the first step is figuring out how to instruct it to draw basic color data, pixel by pixel. To do this we use the companion methods <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createImageData">createImageData</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/putImageData">putImageData</a>. createImageData generates a Uint8ClampedArray that represents the pixels in the canvas. By manipulating the elements of that array, it’s possible to set pixel color values that can then be rendered usingputImageData.</p><h3>The Hello World of images</h3><p>Setting the color of a particular pixel is conceptually simple: simply put that color data into the image data array at the right spot. Figuring out the correct position is tricky, though. The image is two-dimensional, but the data array is one-dimensional (flat). It represents each pixel in the image going across the rows from left to right, starting in the upper left corner. Furthermore, each pixel is represented with integers in <em>four</em> spots in the array (for red, green, blue and alpha values). So the r,g,b,a values of the upper-leftmost pixel are represented by the first four indices in the array. If you have a 100-pixel-wide image, for example, the first 400 indices in the array represent the rgba values of the pixels across the top row. The rgba values of the leftmost pixel of the <em>second</em> row start at the 400th index (and continue through the 403rd).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*TO1GHpPpuM8a8zaAL69fAw.png" /></figure><p>Let’s make a 100x100 canvas and just shove a bunch of red pixels into it. The image data array will have a length of 100 by 100 by 4, and we’ll iterate through it, putting 255 into every 1st pixel (for “full” red) and 255 into every 4th pixel (for “full” alpha—completely opaque):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4637d95bf90e2f49bfdef80e99babf33/href">https://medium.com/media/4637d95bf90e2f49bfdef80e99babf33/href</a></iframe><p>I won’t embed a codepen that only shows a red square (I trust you can envision it), but you can <a href="http://codepen.io/bantic/pen/jyroEe?editors=0010">click through</a> to check it out if you’re so inclined.</p><p>This is a good initial start that we can already play around with in fun ways. Let’s bind the r, g, b, and a values to sliders. Every pixel in our square is still the same color, but we can explore the RGB color space this way:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodepen.io%2Fbantic%2Fpen%2FoBLRVG%3Feditors%3D0010&amp;src=https%3A%2F%2Fcodepen.io%2Fbantic%2Fembed%2Fpreview%2FoBLRVG%3Fheight%3D600%26amp%3Bslug-hash%3DoBLRVG%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;type=text%2Fhtml&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab3c8055e4acbf7cda8059c2203d1851/href">https://medium.com/media/ab3c8055e4acbf7cda8059c2203d1851/href</a></iframe><p>Quick: Try to make yellow. Now try orange.</p><h4>An aside on color theory</h4><p>It may or may not be surprising that moving all sliders to the right (100% red, green and blue) yields <em>white</em>. This is because RGB is an <a href="https://en.wikipedia.org/wiki/Additive_color">additive color model</a>, which behaves as though you are combining <em>light</em> of the various colors. And white light is what you get when you mix red, green and blue light. That’s why you see a rainbow bend out of a prism: those colors are already present in the “white” light.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*LnZ1EuNhdNBNS9ZYAE-qpw.jpeg" /><figcaption>Source: <a href="https://www.flickr.com/photos/filipesaraiva/21398918734/in/photolist-yAX41J-dV3xq8-iEqBS5-mJn3eQ-oGw1dP-ankNuQ-iEgxgt-oGwPfU-91CgsT-dC5yd7-iEmHnF-dafkiR-7atEEb-afrFLD-8HRzcB-hjipTp-dFRThN-8HUJiy-8HUHf1-8bFfmG-eMyiba-8UKPzT-ehSHA2-fhEJri-3tsbar-7uW6gT-fhFkSc-ogwc9n-HLLaZb-aRrK76-9CkD6N-aRrDZn-wanCST-v8bCuf-P5atgD-PFaxA7-NtrFfr-NwzXsk-N4YUjc-Km5sXS-GZpHUf-yesVGn-aMgTNv-kEYir5-bASdSb-cdUVQ1-fhTLmQ-e5wC2N-7uW6gX-dLGTMr">Filipe Saraiva</a></figcaption></figure><p>If you try mixing colors that are in a <a href="https://en.wikipedia.org/wiki/Subtractive_color"><em>subtractive</em> color model</a>, such as paint, equal parts of red, green and blue will not combine to make white. Recall finger painting as a child—after swirling around all the colors into a great goopy mess you end up with a brownish/blackish hue. A common subtractive color palette is cyan, magenta, yellow and black (CMYK; the k is black and stands for “key”). Does it seem odd that RGB can apparently make all the colors using only 3 variables but CMYK seems to require 4? Well, C, M and Y <em>are</em> enough in theory to make all colors (including black), but messy reality gets in the way when printing, and the black that results from evenly mixing equal amounts of cyan, magenta and yellow is “unsatisfactory”—not a very deep black. In addition, black stuff (like text) is common when printing and it’s cheaper to use only a single ink (the black one) instead of 3. There are several other <a href="https://en.wikipedia.org/wiki/CMYK_color_model#Benefits_of_using_black_ink">benefits of using black ink</a>.</p><p>If you play around further with the codepen above you’ll see that the additive and subtractive color models are correlated: cyan, magenta and yellow are the result of combining each two-item combination of R,G and B.</p><p>We’ve now covered the basics of pixel manipulation in canvas, along with an iota of color theory. We’ll return to color soon, but for now we’re moving on to the “wheel” part of color wheel. Let’s draw a circle.</p><h3>Draw a circle</h3><p>A circle is defined by its radius. Everything that is within the radius’s distance from the circle’s center is in the circle, everything that is farther away is out of it. Pretty straightforward. Our next task, then, is to figure out how far away every pixel in our square is from the center, and skip all the ones that are outside the circle. This is the first time we’ve had to think about the location of the pixels, and to simplify our ability to do that, we’re going to change the way we loop through the pixels. Our code used to be one single loop from 0 to 40,000 (100 pixels by 100 pixels by 4 values per pixel), in groups of 4. When we draw a circle, it’s easiest if we use an x-y coordinate system where the origin is the center of the circle. When we do this it’s much simpler to figure out the distance from any (x,y) point to the center. We do it by employing a 2000-year-old formula: the <a href="https://en.wikipedia.org/wiki/Pythagorean_theorem">pythagorean theorem</a>.</p><p>If you have a point (x,y) and you imagine a line from it vertically to the x-axis (call this line <em>a</em>) and another one horizontally to the y-axis (call it <em>b</em>), a line to the center forms the hypotenuse (line <em>c</em>) of a right triangle with those two other lines. Solve the pythagorean theorem for <em>c</em> to get that distance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*dmF2w-tRAyixw4MGT9juGw.png" /></figure><pre>a^2 + b^2 = c^2</pre><p>In JavaScript, then:</p><pre>let distance = Math.sqrt(x*x + y*y);</pre><p>Updating the draw function to now be drawCircle, with a new x-y coordinate system centered at (0,0), we have:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0768336281c6ea67d30776d6f68ef195/href">https://medium.com/media/0768336281c6ea67d30776d6f68ef195/href</a></iframe><p>Since our circle’s radius is 50 pixels, we loop the x and y values from -50 to 50 symmetrically around a central (0,0) origin. This simplifies the calculation of the distance of the (x,y) coordinate but complicates the part of the code where we figure out what index in the image data array corresponds to that pixel. This wasn’t a problem before when we were only looping from 0 to 40,000. To translate from the coordinates used in our loop to those in the data array, we first adjust each <em>x</em> and <em>y</em> value by adding the radius to translate them from the range [-50,50] to [0,100]. Then multiply the adjusted <em>y</em> value by the length of a single row of the canvas (100 pixels, in this case) and add the adjusted x value. Finally, because each pixel is represented by 4 values in the array, multiply by pixelWidth (4). This is the line of code that calculates the index in the pixel data array:</p><pre>let index = (adjustedX + (adjustedY * rowLength)) * pixelWidth;</pre><p>And here’s the same pen as before, with the new code from above:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodepen.io%2Fbantic%2Fpen%2FvgKqPw%3Feditors%3D0011&amp;src=https%3A%2F%2Fcodepen.io%2Fbantic%2Fembed%2Fpreview%2FvgKqPw%3Fheight%3D600%26amp%3Bslug-hash%3DvgKqPw%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;type=text%2Fhtml&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/77212938b7568673de1748dc8b068292/href">https://medium.com/media/77212938b7568673de1748dc8b068292/href</a></iframe><p>To recap:</p><ul><li>We can put a pixel of any RGB color of our choosing onto the canvas at any (x,y) coordinate that we desire.</li><li>We can restrict our output to a circle.</li></ul><p>As a reminder, here’s the goal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/211/1*gfI4SzYRaVKbJkZ3Xd-2uQ.png" /></figure><p>How can we map each point in the circle to a color such that there is a smooth transition of the hue as we sweep 360 degrees around? To do this effectively, we need a color system that is more of a natural fit for this visual representation. We’ll abandon RGB temporarily and take a look at a color system based on hue, saturation and value, aka HSV. This is a cylindrical-coordinate color system where hue maps directly to the degrees of a circle. This is perfect for making a color wheel!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*trbJOac0vYLTM88tdwe1tQ.png" /><figcaption>HSV cylindrical representation. <a href="http://By HSV_color_solid_cylinder.png: SharkD derivative work: SharkD  Talk (HSV_color_solid_cylinder.png) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0) or GFDL (http://www.gnu.org/copyleft/fdl.html)], via Wikimedia Commons">Source</a></figcaption></figure><h4>RGB: The color cube</h4><p>We certainly <em>could</em> attempt to map RGB colors such that they smoothly transition around our circle, but it would be quite hard. If you consider that RGB was designed to map to a <em>cube</em>, you can understand why that might make it less straightforward to map those colors to a circle instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rVK1NhtB3sJkAz7yw7Gemg.png" /><figcaption>RGB Color cube. <a href="http://By RGB_farbwuerfel.jpg: Horst Frank RGB_color_solid_cube.png: SharkD derivative work: SharkD  Talk (RGB_farbwuerfel.jpg RGB_color_solid_cube.png) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons">Source</a></figcaption></figure><p>For a better visual understanding of why <em>hue</em> works so well for our purposes, we’ll start by redoing the RGB sliders example from above to use HSV sliders instead. Unfortunately, the data that we render to the canvas using putImageData still requires that we set r,g,b,a values, not h,s,v values. So we have to write a function that translates between the two. Here’s the code. If you want to understand it better I’ll direct you to the <a href="https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV">HSL and HSV</a> article on wikipedia.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f8d963b11754a2014867d7822efde2a/href">https://medium.com/media/9f8d963b11754a2014867d7822efde2a/href</a></iframe><p>Try playing with this codepen that uses HSV sliders. If you drag the hue slowly from left to right you’ll see the square change smoothly from red through the rainbow and back to red. Notice that the rgb values change a bit more haphazardly.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fbantic%2Fembed%2Fpreview%2FEZgNxq%3Fheight%3D600%26amp%3Bslug-hash%3DEZgNxq%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fbantic%2Fpen%2FEZgNxq%3Feditors%3D0010&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F170883.EZgNxq.small.8971a1b2-1caf-4b19-b3e9-507d3688b9b9.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/0935e86bddfeaee5397e3d62bc986529/href">https://medium.com/media/0935e86bddfeaee5397e3d62bc986529/href</a></iframe><p>Ok, we can map HSV color to RGB values so that we can display it on our canvas. How do we map each (x,y) point in the circle to a hue value? Or, to be more precise, how do you figure out the angle of each (x,y) point?</p><p>The answer: <a href="https://en.wikipedia.org/wiki/Polar_coordinate_system">polar coordinates</a>! Just as (r,g,b) uses cartesian coordinates and (h,s,v) ended up being more useful for our circular space because it uses cylindrical coordinates, polar coordinates are the best tool for exploring a 2-dimensional space circularly. Each pixel in an (x,y) system is located by its distance to the right (x-axis) and up (y-axis) from the origin, in a polar coordinate system each pixel is defined by its distance from the origin (r) and its angle (phi).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*OiSq1wSk4nUF1gZeZyYLCQ.png" /></figure><p>That said, the canvas pixel data array is still organized for (x,y) pixels, so when it comes time to render onto the canvas we’ll have to map those (x,y) coords into polar ones. We actually are half-way there already — the distance calculation we did for the circular codepen above gives the <em>r</em> value for each point. We are only missing the angle <em>phi </em>for each point. To do so, remember the triangle that the (x,y) point makes with the origin, and take the arctangent of the two orthogonal sides of it: phi = arctangent(dy, dx). JavaScript implements arctangent with the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2">Math.atan2</a> function that returns results in <em>radians </em>in the range [-π,π]. We’re mapping the hue to degrees of the circle, though, so we have to convert radians to degrees.</p><p>Check it out!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fbantic%2Fembed%2Fpreview%2FzNKopG%3Fheight%3D600%26amp%3Bslug-hash%3DzNKopG%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fbantic%2Fpen%2FzNKopG%3Feditors%3D0010&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F170883.zNKopG.small.3670327c-c74f-45f8-83e6-da308f3ce321.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5715a741829eb4837df94c0e85e312c/href">https://medium.com/media/a5715a741829eb4837df94c0e85e312c/href</a></iframe><p>Awesome. We are basically there, but you’ll notice that the colors come to a bit of a discontinuous pinch point in the center. This would look nicer if they all blended nicely there. We want the colors to be most vibrant at the edge and fade to white in the center. So far we’ve only varied the HSV of each (x,y) pixel by its angle (<em>phi</em>) — now we’ll make each pixel’s color a function of both the angle and its distance (<em>r</em>). The <em>hue</em> is still mapped to degree, and now the <em>saturation</em> will be mapped to distance, from 0.0 (in the center) to 1.0 at the edge of the circle.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fbantic%2Fembed%2Fpreview%2FvgyBWx%3Fheight%3D600%26amp%3Bslug-hash%3DvgyBWx%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fbantic%2Fpen%2FvgyBWx%3Feditors%3D0010&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F170883.vgyBWx.small.0c1ce6aa-12a2-4152-9557-0e0c3fbdccad.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/06db853a83c971fd72296efbe86d08c2/href">https://medium.com/media/06db853a83c971fd72296efbe86d08c2/href</a></iframe><p>Voila!</p><p><strong>Bonus</strong>: Let’s spice this up by animating a new property that I’m calling <em>swirl</em>, which shifts the hue by an amount that increases the farther away the pixel is from the center. Building animations into the color wheel will be the topic of a future post.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodepen.io%2Fbantic%2Fpen%2FpRNzpG%3Feditors%3D0010&amp;src=https%3A%2F%2Fcodepen.io%2Fbantic%2Fembed%2Fpreview%2FpRNzpG%3Fheight%3D600%26amp%3Bslug-hash%3DpRNzpG%26amp%3Bdefault-tabs%3Djs%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;type=text%2Fhtml&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/83cdd3e5c43cef405df5d8bfda1e2ea6/href">https://medium.com/media/83cdd3e5c43cef405df5d8bfda1e2ea6/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78256c9d7d43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Things to Know When Building an Ecommerce Mobile Web App]]></title>
            <link>https://medium.com/ecommerce-magazine/things-to-know-when-you-build-an-ecommerce-mobile-web-site-a3d260808eac?source=rss-36f8e59ad65f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3d260808eac</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[android-pay]]></category>
            <category><![CDATA[apple-pay]]></category>
            <category><![CDATA[ecommerce]]></category>
            <category><![CDATA[stripe]]></category>
            <dc:creator><![CDATA[Cory Forsyth]]></dc:creator>
            <pubDate>Tue, 24 Jan 2017 17:14:25 GMT</pubDate>
            <atom:updated>2017-11-10T18:39:38.948Z</atom:updated>
            <content:encoded><![CDATA[<p>Our team at <a href="http://www.201-created.com/">201 Created</a> recently built a best-in-class mobile web app to see how far we could push the boundaries of cutting-edge browser APIs and have our web app achieve feature parity with a similar native app. You can try it out; it sells stickers: <a href="https://www.shop-201.com/">www.shop-201.com</a> (best viewed on a mobile browser like mobile Safari).</p><p>If you are interested in accepting payments on the mobile web, the following lessons may be useful to you.</p><h3>Your site must be served securely via https</h3><p>This should be obvious. Apple Pay, the PaymentRequest API, and payment processors like Stripe will all refuse to operate when run from an insecure domain.</p><p>Luckily it’s very easy to set up your own <a href="https://medium.com/@bantic/free-tls-with-letsencrypt-and-heroku-in-5-minutes-807361cca5d3#.x3sq1mwka">TLS certificate for free with LetsEncrypt</a>. If you’re using Ember or Rails (like we did), here are some <a href="https://medium.com/@bantic/serving-ember-and-rails-locally-with-ssl-tls-44640f615b95#.6twxexvio">notes on serving those locally via TLS</a>, which is necessary if you want to make test payments locally.</p><h3>Apple Pay goes nicely with a helping of Stripe</h3><p>Stripe’s <a href="https://stripe.com/docs/apple-pay/web">Apple Pay on the web documentation</a> is great, and a darn sight simpler than Apple’s Apple Pay on the web documentation.</p><p>There are a few other Apple Pay-related gotchas to look out for, however:</p><h4>Gotchas regarding creating a Sandbox Tester (Step 1 of Stripe’s Docs)</h4><p>Stripe doesn’t tell you this, but in order to create a usable Sandbox Tester (part of the Step 1 steps in Stripe’s docs), you need to do two things:</p><ul><li>Verify the user’s email. (Even though this is a test user you’ll need to give them a real email — and then you’ll need to check their email account and click the verify link that Apple emails to you)</li><li>Visit <a href="http://icloud.com/">icloud.com</a> and sign is as the test user so that you can accept the Payment terms of service (it will be presented to you after logging in).</li></ul><p>If you don’t follow those two steps the login process on your iDevice will fail in odd ways (either telling you the login info is incorrect, or putting you into a “you must update your password” infinite loop).</p><p>At this point you have a usable Sandbox Tester that should be usable to to log into iCloud on XCode’s iOS Simulator with. Another gotcha: Stripe suggests adding a test credit card, but you cannot do this on the simulator. It will seem tantalizingly possible, but neither test credit card nor real credit card will be accepted by the simulator, so don’t bother (and it doesn’t matter if you attempt to add the card via the Wallet or via the iCloud screen — both ways won’t work).</p><p>If you’re using your own iDevice for testing and have seen the dire warnings about data loss when signing out of iCloud, but have thrown caution to the winds and signed out anyway so that you can sign in with the test card, good for you! You will be able to add a test credit card.</p><p>Testing on the iOS simulator <em>will</em> work if you are using your Stripe <em>test </em>keys, although you’ll get this somewhat unsatisfying “Pay with passcode” option instead of the fingerprint icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*0zvb38995MMqV5b_VzjxXg.jpeg" /><figcaption>Making a test Apple Pay payment on the simulator</figcaption></figure><p>If you attempt to make a <em>real </em>payment when logged into a sandbox tester iCloud, you’ll see this message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*kBkISPhk0DWj61D9cG8dLA.jpeg" /></figure><h4>iOS Add To Home Screen Caveats</h4><p>Luckily no one really uses the “add to home screen” functionality in iOS, but if you do, there are a few gotchas to be aware of.</p><p>Firstly, Apple Pay isn’t available if you run the app from the home screen. This is either a problem with the code Stripe provides to detect Apple Pay availability, or simply a lack of that API being provided by the frame that runs the app. Either way, this is a good place to use Stripe’s simple checkout code instead.</p><p>Secondly, Stripe’s checkout has a nifty 2FA modal that pops up with 6 blank spaces for you to type in the 2FA code that they SMS you when you attempt to make a purchase. Unfortunately, after switching away from the home-screened app to iMessage and back, the modal will have disappeared. Stripe suggests using the lower-level Stripe payment APIs instead of their Checkout.js for this case.</p><h3>Android Pay is a “potemkin village”</h3><p>Even though Google’s own documentation about <a href="https://developers.google.com/web/fundamentals/discovery-and-monetization/payment-request/android-pay#gateway_token_approach">using the </a><a href="https://developers.google.com/web/fundamentals/discovery-and-monetization/payment-request/android-pay#gateway_token_approach">PaymentRequest API</a> on the web shows demo code that uses Stripe as the gateway token provider, Stripe has confirmed that this code will not work in production. They suggest that support is “in the works” but no ETA has been provided. However, the test code they show <em>does</em> work, in case you are planning on building a business around people pretending to pay you.</p><h3>mixonic on Twitter</h3><p>Braintree&#39;s support too. I tweeted at the Google dev who wrote the docs, no response. This is Potemkin village of parity with ApplePay.</p><p>We’ve reached out to Braintree support as well and have conflicting reports about whether the same gateway token approach can be made to work on with Braintree.</p><p>All in all, it’s clear that although there is definite work being put in by both the Android team and payment providers, there’s still a gap between expectation and reality. It seems quite likely that one day (soon?) you will be able to accept Android Pay payments on the web, but today does not appear to be that day. If you have it figured out, or know of a site that does this today, please let me know!</p><p>Want to learn more about 201 Created? <a href="http://twitter.com/two_oh_one">Follow us on twitter</a> or send an email to <a href="/service/mailto:hello@201-created.com">hello@201-created.com</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F258a36%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F258a36%2F&amp;image=https%3A%2F%2Fe.enpose.co%2F%3Fkey%3DdRXnS9Gplk%26w%3D700%26h%3D425%26url%3Dhttps%253A%252F%252Fupscri.be%252F258a36%252F%253Fenpose&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/515b1104f6398da8f1a6742d433c2339/href">https://medium.com/media/515b1104f6398da8f1a6742d433c2339/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3d260808eac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ecommerce-magazine/things-to-know-when-you-build-an-ecommerce-mobile-web-site-a3d260808eac">Things to Know When Building an Ecommerce Mobile Web App</a> was originally published in <a href="https://medium.com/ecommerce-magazine">Ecommerce Magazine</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serving Ember and Rails locally with SSL/TLS]]></title>
            <link>https://medium.com/@bantic/serving-ember-and-rails-locally-with-ssl-tls-44640f615b95?source=rss-36f8e59ad65f------2</link>
            <guid isPermaLink="false">https://medium.com/p/44640f615b95</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[ember]]></category>
            <dc:creator><![CDATA[Cory Forsyth]]></dc:creator>
            <pubDate>Wed, 18 Jan 2017 22:53:59 GMT</pubDate>
            <atom:updated>2017-01-31T18:51:11.666Z</atom:updated>
            <content:encoded><![CDATA[<p>(After you’re done reading this article, be sure to check out our article on <a href="https://medium.com/@bantic/free-tls-with-letsencrypt-and-heroku-in-5-minutes-807361cca5d3#.v722qea3h">setting up TLS for free with LetsEncrypt and Heroku</a>.)</p><p><strong>Update Jan 24 2017:</strong> Changed the recommended common name to localhost.ssl — using localhost alone can cause the browser to cache the https which causes some problems.</p><p>If you are writing an Ember app that requires that your connection be secured, there is a bit of setup you will need to do in order to serve connections via https locally. This was the case recently when our team at <a href="https://www.201-created.com/">201 Created</a>, built a proof-of-concept progressive web app that accepted Apple Pay. This post outlines the approach we took to set up both our ember app and rails apps to serve via TLS*.</p><p>Luckily, ember-cli already has an “ssl” configuration option, so all you need to do is turn that option on and provide your own certificate and key. Because your app is running locally, a self-signed certificate will suffice.</p><h4>Step 1: Generate a self-signed cert</h4><p>Heroku has a <a href="https://devcenter.heroku.com/articles/ssl-certificate-self">nice guide to creating a self-signed certificate</a> via the command line, or you can copy-paste the lines (one at a time) below:</p><pre>openssl genrsa -des3 -passout pass:x -out server.pass.key 2048<br>openssl rsa -passin pass:x -in server.pass.key -out server.key<br>rm server.pass.key<br>openssl req -new -key server.key -out server.csr</pre><p>The last command will prompt you with some questions. Your answers to these questions don’t matter very much <em>except</em> for the Common Name, which should be <em>localhost.ssl</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*Lg6oOJQl6JHObwIjrIpBEA.jpeg" /><figcaption>Prompts for certificate properties</figcaption></figure><p>At this point you have generated key and certificate signing request files. The last step is to use these two files to sign your certificate yourself (this is where the “self-signed” part of “self-signed cert” comes in):</p><pre>openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt</pre><p>You can delete the certificate signing request file (<em>server.csr</em>) now, but keep the <em>server.key</em> and your new cert <em>server.crt</em> handy<em>.</em></p><h4>Step 1b: Update /etc/hosts</h4><p>We used <em>localhost.ssl</em> as the common name, so you’ll want to edit your /etc/hosts file so that it points at your local host. Add this line to the hosts file:</p><pre>127.0.0.1                  localhost.ssl</pre><p>etc/hosts is a protected file so you’ll need to use sudo to edit it.</p><h3>Step 2: Use your certificate with ember-cli</h3><p>By default, ember-cli will look for your certificate and key in a directory named <em>ssl</em> in the root of your project. Go ahead and create the <em>ssl</em> directory and move your<em> server.key </em>and <em>server.crt </em>files into it. Next, edit your <em>.ember-cli</em> file (located in the root of your project) to have the setting&quot;ssl&quot;: true.</p><h3>Step 3: Trust your certificate</h3><p>Start your ember app by running ember serve and open <a href="https://localhost.ssl:4200/">https://localhost.ssl:4200</a> in Safari. You’ll see this warning message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*dbNIUTWAhcmzTfIvvIMJYg.jpeg" /><figcaption>Check the box to trust your certificate.</figcaption></figure><p>Check that <em>Always trust “localhost.ssl” </em>box and hit continue. At this point your ember app is running via TLS!</p><p>Note: You <em>do</em> need to use Safari to get that “trust” checkbox. Chrome and Firefox don’t have a mechanism allow you to trust the certificate. This is because Safari will update your OS X Keychain.</p><p>If for you don’t want to do this through Safari, or you have trouble doing so, you can instead add it directly to your keychain by opening up the <em>Keychain Access, </em>dragging in the <em>server.crt,</em> and double-clicking it to choose to “Always Trust” it. This has the same effect.</p><h3>Step 4 (optional): Run rails over TLS</h3><p>If you have a rails app that you run locally to provide a backend for your ember app, you’ll want to run it over TLS as well.</p><p>You can use the same cert and key files that you generated in the previous steps. Simply copy both <em>server.key </em>and <em>server.crt</em> to a directory in your rails app (we use a <em>ssl</em> directory in the project root for symmetry with the ember app, but you can put it wherever you want).</p><p>We use <a href="https://github.com/puma/puma">puma</a> to run our rails apps locally, and puma also allows you to configure TLS usage. First, ensure you have added <em>puma</em> to your <em>Gemfile</em>, and then, to direct puma to serve TLS, use the <em>bind</em> flag, <strong>-b :</strong></p><pre>puma -b &#39;ssl://127.0.0.1:3000?key=<strong>ssl/server.key</strong>&amp;cert=<strong>ssl/cert.crt</strong>&#39;</pre><p>Update the <em>key</em> and <em>cert</em> parameters to match your file paths if you didn’t put the files in the <em>ssl</em> directory.</p><p>If you use <a href="https://github.com/ddollar/foreman">foreman</a> to run your app (which you should), you can store the puma configuration parameters in a local Procfile. Add a <em>Procfile.dev</em> file in your project root with the puma configuration:</p><pre>web: puma -b &#39;ssl://127.0.0.1:3000?key=<strong>ssl/server.key</strong>&amp;cert=<strong>ssl/cert.crt</strong>&#39;</pre><p>Now you can start up your rails server with foreman:</p><pre>bundle exec foreman start -f Procfile.dev</pre><p>Now visit your rails app at <a href="https://localhost:3000/">http<strong>s</strong>://localhost:3000</a>. Because you’re reusing the same self-signed cert that you’ve already trusted, you should be all set! Bask in the warmth of the green lock icon.</p><ul><li><em>I’m pedantically using TLS because it is the technically correct term, even though SSL is still quite common. (TLS is the IETF name, SSL is the old name invented by Netscape.) For the purposes of this article the terms are more similar than they are different, so feel free to </em><em>s/TLS/SSL/g in your mind if that’s your preference.</em></li></ul><p>Want to hear more about 201 Created and what we do? Follow <a href="https://twitter.com/two_oh_one">201 Created</a> on twitter or drop us a line: <a href="/service/mailto:hello@201-created.com">hello@201-created.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44640f615b95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Free TLS with LetsEncrypt and Heroku in 5 Minutes]]></title>
            <link>https://medium.com/@bantic/free-tls-with-letsencrypt-and-heroku-in-5-minutes-807361cca5d3?source=rss-36f8e59ad65f------2</link>
            <guid isPermaLink="false">https://medium.com/p/807361cca5d3</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[lets-encrypt]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <dc:creator><![CDATA[Cory Forsyth]]></dc:creator>
            <pubDate>Thu, 12 Jan 2017 22:14:05 GMT</pubDate>
            <atom:updated>2018-07-27T14:52:23.778Z</atom:updated>
            <content:encoded><![CDATA[<p>Our team at <a href="https://www.201-created.com/">201 Created</a> recently built a proof-of-concept web app that showcases the extraordinary capabilities of the modern web. It is quickly converging on (and in some cases, surpassing) the feature set of native apps. We will be releasing the web app soon, along with more blog posts about our process; to stay tuned, follow <a href="https://twitter.com/bantic">@bantic</a> (me) or <a href="http://twitter.com/two_oh_one">201 Created</a>.</p><p><strong>Update July 27 2018</strong>: A few readers have pointed out that this approach no longer works for apps on the free tier at Heroku. The bad news is that there is no longer a zero-cost way to deploy a Heroku app with TLS. The good news is that it is even easier, provided you upgrade to a (paid) hobby dyno or greater, to use <a href="https://devcenter.heroku.com/articles/automated-certificate-management">Heroku’s Automated Certificate Management</a> system to turn on TLS for your app.</p><p>Our web app accepts payments via Apple Pay (pay with your fingerprint!) and Android Pay, and in order to do so we must serve the app securely with <a href="https://en.wikipedia.org/wiki/Transport_Layer_Security">TLS</a> (aka http<strong>s</strong> and, erroneously, SSL). In the past this would entail buying an TLS Certificate from one of the providers online and jumping through a few hoops to get it assigned.</p><p>These days, however, there’s a new CA (Certificate Authority) on the block: <a href="https://letsencrypt.org/">LetsEncrypt</a>. They are a non-profit that launched in April, 2016, and are dedicated to allowing everyone to secure their website with TLS. LetsEncrypt now supports more than 20 million active certificates and is rapidly growing.</p><p>If you host your website on Heroku with a custom domain and haven’t yet secured your site with TLS, now is the time. The process takes less than 5 minutes and is completely free if you have a Heroku account that uses paid dynos (Hobby and up). See more details about Heroku’s free SSL <a href="https://devcenter.heroku.com/articles/ssl">here</a>.</p><h4>Step 1: Install certbot</h4><p>The first step is to<strong> install the command-line tool <em>certbot</em></strong><em>. </em>If you are on Mac and use homebrew, installation is simple:</p><pre>brew install certbot</pre><p>For other OSes, see the <a href="https://certbot.eff.org/docs/install.html">certbot installation docs</a>.</p><p>(Note: this post was tested with certbot version 0.9.3. If your version is significantly different you may need to adjust some commands below.)</p><p>After certbot is installed, generate a cert manually:</p><pre>sudo certbot certonly --manual</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*w6n6VG49yJAmeOSR3Jv5MA.png" /><figcaption>Enter the domain name of your site as prompted.</figcaption></figure><p>After you hit ok you may be notified that your IP is logged. If so, hit ok again. At this point certbot will display the ACME challenge information: A URL and its required text content. It looks like this:</p><pre>Make sure your web server displays the following content at<br>http://www.my-site.com/.well-known/acme-challenge/&lt;long-string&gt;:</pre><pre>&lt;long-string&gt;.&lt;other-long-string&gt;</pre><h4>Step 2: Upload static file</h4><p><strong>Before you continue, </strong>you must configure your server at heroku such that it returns the given string for the given URL. If you are using rails you can put a file in the public directory and it will be served statically:</p><pre>$ mkdir -p public/.well-known/acme-challenge/</pre><pre>$ echo &quot;&lt;long-string&gt;.&lt;other-long-string&gt;&quot; &gt; public/.well-known/acme-challenge/&lt;long-string&gt;</pre><p>The same principle applies for other types of serving software. Put that file in your public or similar directory (or configure a route in your application to serve this file). After you’ve put the static file in place, commit the changes and push them to heroku.</p><p>This step also requires that you have your custom domain (in the example above we are using <em>www.my-site.com</em>) set up at heroku. If you haven’t done this yet, you’ll need to do so before you can continue. This involves telling Heroku about the custom domain and setting a DNS CNAME record. See <a href="https://devcenter.heroku.com/articles/custom-domains">Heroku’s docs on custom domains</a> for more details.</p><p>At this point you should be able to visit the url that certbot displays (e.g.: http://www.my-site.com/.well-known/acme-challenge/&lt;long-string&gt;) in your browser and see the correct string of text. When that is the case, hit enter and let certbot verify that you control this domain.</p><p>If all goes well you will see:</p><pre>IMPORTANT NOTES:<br> - Congratulations! Your certificate and chain have been saved at<br>   /etc/letsencrypt/live/www.my-site.com/fullchain.pem. Your<br>   cert will expire on 2017-04-12.</pre><h4>Step 3: Upload cert to heroku</h4><p>Now, <strong>upload the certificate and private key</strong> to heroku. The heroku command-line tool will do this for you. Copy and paste the following command, replacing the domain name for the one you are using.</p><p>The command requires two arguments: the path to your certificate and the path to your key:</p><pre>heroku certs:add path/to/cert path/to/key</pre><p>Certbot will have placed both files in /etc/letsencrypt/live, so copy and paste the command below, replacing the bold text for the domain name you are using (same name, including ending “.com” or other tld, that you entered in the first step of generating the cert):</p><pre>sudo heroku certs:add /etc/letsencrypt/live/<strong>domain</strong>/fullchain.pem /etc/letsencrypt/live/<strong>domain</strong>/privkey.pem</pre><p>After heroku accepts the uploaded cert, you are all set! Visit http<strong><em>s</em></strong>://yourdomain.com and bask in the glory of the green lock icon.</p><p>Before you go, remember to take note of the certificate expiration date and add a reminder so that you don’t forget to renew it. The command to renew your cert is:</p><pre>sudo certbot renew --manual</pre><h4>Links</h4><p>Some other links worth reading:</p><ul><li><a href="https://letsencrypt.org/2017/01/06/le-2016-in-review.html">LetsEncrypt 2016 Year In Review</a> — look at that hockey stick!</li><li><a href="https://devcenter.heroku.com/articles/ssl">Heroku SSL Docs</a></li><li><a href="https://devcenter.heroku.com/articles/custom-domains">Heroku Custom Domain Docs</a></li><li><a href="https://letsencrypt.org/how-it-works/">LetsEncrypt: How it works</a></li><li><a href="https://letsencrypt.github.io/acme-spec/">ACME Challenge spec</a> — For the very curious. Note that HTTP challenge (which we used here) is only one of several types that the spec supports. Another common one is the DNS challenge, which involves adding a specific DNS record for your domain.</li></ul><p>Did these steps work for you? Are you now running your site over https? Please let me know in the comments. If you’d like to see our follow-up blog posts about the web app we are building, follow <a href="http://twitter.com/bantic">me</a> or <a href="http://twitter.com/two_oh_one">201 Created</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=807361cca5d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[More OAuth 2.0 Surprises: The Refresh Token]]></title>
            <link>https://medium.com/@bantic/more-oauth-2-0-surprises-the-refresh-token-1831d71f4af6?source=rss-36f8e59ad65f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1831d71f4af6</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[oauth]]></category>
            <dc:creator><![CDATA[Cory Forsyth]]></dc:creator>
            <pubDate>Fri, 15 Jan 2016 20:02:11 GMT</pubDate>
            <atom:updated>2016-01-15T20:04:18.100Z</atom:updated>
            <content:encoded><![CDATA[<p>Last week I wrote a post about some of the <a href="https://medium.com/@bantic/some-surprising-things-about-oauth-2-0-7a328f1b4952#.ykjjntqua">things about OAuth that have surprised me</a> as I learned more about it for Torii. This is a follow-up post focused on the OAuth 2 <em>refresh token</em>.</p><p>As I explained in the first post, <em>access</em> tokens are the primary goal of an OAuth client. They are what allow you to read/write data on behalf of a user. Access tokens offer a lot of power, however, and when using an OAuth flow to obtain them there is a lot of risk — aspects of the OAuth flow are difficult to secure properly. (There is a very long, very detailed <a href="https://tools.ietf.org/html/draft-ietf-oauth-v2-threatmodel-08">OAuth 2 Threat Model</a> IETF draft that will give you a taste for all the ways thing can go wrong.)</p><p>Since access tokens are so powerful yet also so potentially insecure, their risk is mitigated by giving them short-lived expiration windows. If they’re hard to safeguard properly, at least they don’t last very long. However, this introduces another difficulty for web programmers — how to continue to access data on behalf of your users when their access tokens expire? Enter <em>refresh tokens</em>.</p><p>Refresh tokens can be issued by OAuth providers alongside access tokens. Typically this happens when the OAuth client requests an access scope that warrants long-lived or offline access (often the name of the scope is “<em>offline”, </em>but there’s no specification for this so the value may vary). Refresh tokens can also expire but they often don’t, or have very long expiration times relative to access tokens. Because refresh tokens are more valuable than access tokens they are usually only issued via the OAuth “Authorization Code Grant” flow which uses authenticated backend-server-to-backend-server communication and not via the “Implicit Grant” flow. The OAuth 2 spec doesn’t enforce this, though.</p><p>Note: Auth0 has an excellent write-up about <a href="https://auth0.com/blog/2015/10/07/refresh-tokens-what-are-they-and-when-to-use-them/">refresh tokens and JWTs</a> that is worth reading.</p><blockquote>Misconception: “Refresh tokens refresh an access token.”</blockquote><p>When refresh tokens were first explained to me, I was told something along the lines that a refresh token is used to <strong>refresh</strong> an access token. The word “refresh” certainly implies that that is the case. When I thought about it this way I imagine the access token as a battery-operated toy with dead batteries. It is “stale”, and cannot be used. In order to “refresh” it you replace the batteries and now the freshened toy works again.</p><p>But that is not what a refresh token does. Access tokens <em>do not</em> become stale only to be refreshed later on and reused. Access tokens <em>expire</em>, never to be valid again. A refresh token is not tied to an access token. It is simply used to get a <em>new</em>, valid access token when you need it.</p><p>When do you need a new access token? When the access token you are trying to use is expired or otherwise not valid.</p><p>How do you know when your access token is not valid? By attempting to use it and having the OAuth provider reject it.</p><p>A few more notes on what refresh tokens do and how they can be used:</p><ul><li>Refresh tokens are not connected to access tokens. They do not “refresh” a given access token.</li><li>You do not even provide an access token when using the refresh flow. It just takes a valid refresh token and gives you an access token.</li><li>Refresh tokens are (initially) provided by OAuth providers alongside access tokens in certain circumstances that vary by the provider. Typically you’ll be able to get a refresh token when using the Authorization Code Grant and requesting an “offline” scope.</li><li>Refresh tokens <em>can</em> expire, although their expiration time is usually much longer than access tokens.</li><li>Refresh tokens <em>can</em> become invalid in other ways (for example if your user revokes your OAuth client app’s access — in this case all your refresh tokens and access tokens for that provider would be invalidated).</li><li>If your refresh token is invalid and also don’t have a valid access token for a user, you must send them through an OAuth authorization flow again.</li><li>Refresh tokens cannot be used for read/write access to a user’s information. Only access tokens do this. Refresh tokens are only used to get new access tokens, not read data.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1831d71f4af6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>