<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: James Moore</title>
    <description>The latest articles on DEV Community by James Moore (@knowthen).</description>
    <link>https://dev.to/knowthen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F170658%2Fb76fc300-9045-40a2-932f-5d5095b585fa.jpeg</url>
      <title>DEV Community: James Moore</title>
      <link>https://dev.to/knowthen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/knowthen"/>
    <language>en</language>
    <item>
      <title>Implementing Authorization using Role Based Access Control (RBAC) in Phoenix Web Applications
</title>
      <dc:creator>James Moore</dc:creator>
      <pubDate>Thu, 27 Feb 2020 17:34:57 +0000</pubDate>
      <link>https://dev.to/knowthen/implementing-authorization-using-roll-based-access-control-rbac-in-phoenix-web-applications-3k9p</link>
      <guid>https://dev.to/knowthen/implementing-authorization-using-roll-based-access-control-rbac-in-phoenix-web-applications-3k9p</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/6TlcVk-1Tpc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Authorization in Phoenix web applications
&lt;/h2&gt;

&lt;p&gt;Here's an exchange I've had on a few occasions when discussing a new&lt;br&gt;
web app project:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.knowthen.com%2Fstatic%2F50f247878e7e0f8f10a2a1ff3a877dc4%2Fe85cb%2Fauthorization-conversation.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.knowthen.com%2Fstatic%2F50f247878e7e0f8f10a2a1ff3a877dc4%2Fe85cb%2Fauthorization-conversation.png" alt="Authorization Conversation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, I can't blame Bob for not wanting to talk about security and&lt;br&gt;
authorization, it's not interesting or fun, however dodging these types of&lt;br&gt;
questions can leave us, developers, in a tough spot.&lt;/p&gt;

&lt;p&gt;So what do you do in a situation like this, where the details are vague, but&lt;br&gt;
you've got to start implementing something?&lt;/p&gt;

&lt;p&gt;Well, you need to be careful, because you're facing a couple of big risks.&lt;/p&gt;

&lt;p&gt;Without clear direction, you might end up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding too few authorization features &lt;/li&gt;
&lt;li&gt;or adding unnecessary authorization features.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's my suggestion, for dealing with authorization when the requirements&lt;br&gt;
are vague.&lt;/p&gt;

&lt;p&gt;Choose an approach that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;is simple and well understood &lt;/li&gt;
&lt;li&gt;is widely adopted &lt;/li&gt;
&lt;li&gt;follows the 80/20 rule (on features)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;So what approach is simple and well understood?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This would have to be Role Based Access Control (RBAC), which is been around&lt;br&gt;
for almost 3 decades. RBAC doesn't solve every authorization problem you&lt;br&gt;
might have, but it is relatively simple, and well understood.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So what's the most widely adopted approach?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, that would have to be Role Based Access control as well, in fact, most&lt;br&gt;
larger businesses use some form of Role based access control, in the systems&lt;br&gt;
they use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What do I mean by "follows the 80/20 rule"?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It means, choosing the solution that takes ~20% of the effort, compared to the&lt;br&gt;
more sophisticated options, yet it covers ~80% of the use cases you have.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Role Based Access Control, feels like the perfect 80/20 solution.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, how might you implement Role Based Access control in a Phoenix Web&lt;br&gt;
application?&lt;/p&gt;

&lt;p&gt;Check out the above free screencast to learn more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/knowthen/elixir_authorization_tutorial" rel="noopener noreferrer"&gt;Screencast Git Repo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/introduction-to-phoenix-liveview"&gt;Phoenix LiveView&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/easy-authentication-in-elixir-and-phoenix-with-the-pow-and-pow_assent-libraries"&gt;Authorization In Elixir &amp;amp; Phoenix with pow and pow_assent&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Want to learn more about Elixir &amp;amp; Phoenix?
&lt;/h2&gt;

&lt;p&gt;Checkout my new course: &lt;a href="https://knowthen.com/elixir-and-phoenix-for-beginners" rel="noopener noreferrer"&gt;&lt;strong&gt;Elixir &amp;amp; Phoenix for&lt;br&gt;
Beginners&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>phoenix</category>
      <category>authorization</category>
    </item>
    <item>
      <title>Easy Authentication in Elixir &amp; Phoenix with the pow &amp; pow_assent libraries</title>
      <dc:creator>James Moore</dc:creator>
      <pubDate>Tue, 11 Feb 2020 16:57:45 +0000</pubDate>
      <link>https://dev.to/knowthen/easy-authentication-in-elixir-phoenix-with-the-pow-powassent-libraries-3436</link>
      <guid>https://dev.to/knowthen/easy-authentication-in-elixir-phoenix-with-the-pow-powassent-libraries-3436</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/hnD0Z0LGMIk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up authentication in new Phoenix web apps
&lt;/h3&gt;

&lt;p&gt;I always enjoy starting new web projects, its a nice clean slate and an opportunity for you to create a solution that's hopefully better designed and engineered than the other projects I've worked on... and there are all sorts of interesting things to think about and research, and there's no technical debt to deal with (yet), and there are no pending deadlines, and so on.&lt;/p&gt;

&lt;p&gt;But here's the thing, as soon as I start setting up the new &lt;a href="https://elixir-lang.org/"&gt;Elixir&lt;/a&gt; / &lt;a href="https://www.phoenixframework.org/"&gt;Phoenix&lt;/a&gt; project, my excitement fades pretty quickly, because, in my mind, project setup should take a matter of minutes, but in reality project setups takes much longer than I expect, because... well, it's not something I do every day, so I always have to shake off the dust, do a bit of research to see if there are any new "best practices", or new libraries I should look at and so on.&lt;/p&gt;

&lt;h3&gt;
  
  
  So what?
&lt;/h3&gt;

&lt;p&gt;Ok, so why am I talking about this?&lt;/p&gt;

&lt;p&gt;Well, because sometimes we make these initial setups harder than they have to be, and I want to look at one particular aspect of setting up a new project, that I suspect many of us do the hard way, I know I have.&lt;/p&gt;

&lt;p&gt;The thing I want to look at is handling authentication in a new phoenix project... And I want to consider the question: "how should I handle authentication? roll my own or use a library"&lt;/p&gt;

&lt;p&gt;Check out the above screencast to see my take on handling authentication in Elixir / Phoenix web applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Spoiler alert
&lt;/h3&gt;

&lt;p&gt;Do you want to know the gist of the screencast?&lt;/p&gt;

&lt;p&gt;Even thought it's "easy", you probably shouldn't write your own authentication system, you should just use the excellent &lt;a href="https://github.com/danschultzer/pow"&gt;&lt;strong&gt;pow&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://github.com/pow-auth/pow_assent"&gt;&lt;strong&gt;pow_assent&lt;/strong&gt;&lt;/a&gt; libraries. I make the case for using these libraries and show you how in just a matter of minutes you can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new Phoenix project&lt;/li&gt;
&lt;li&gt;Setup authentication&lt;/li&gt;
&lt;li&gt;Add simple route based authorization&lt;/li&gt;
&lt;li&gt;Setup password resets&lt;/li&gt;
&lt;li&gt;Setup social logins (ie login with Twitter, Facebook, Github, etc)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you like pow &amp;amp; pow_assent, please reach out to the primary author, &lt;a href="http://twitter.com/danschultzer"&gt;Dan Schultzer&lt;/a&gt; and thank him for all his hard work.&lt;/p&gt;

&lt;p&gt;Additionally, if you can, please consider &lt;a href="https://github.com/sponsors/danschultzer"&gt;sponsoring&lt;/a&gt; Dan's open source-work, either personally or through your employer. I believe open source authors are truly under-appreciated, but we can change that if we all chip in just a little bit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Want to learn more about Elixir &amp;amp; Phoenix?
&lt;/h3&gt;

&lt;p&gt;Checkout my new course: &lt;a href="https://knowthen.com/elixir-and-phoenix-for-beginners"&gt;&lt;strong&gt;Elixir &amp;amp; Phoenix for Beginners&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>phoenix</category>
      <category>authentication</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Introduction to Phoenix LiveView</title>
      <dc:creator>James Moore</dc:creator>
      <pubDate>Tue, 05 Nov 2019 23:29:23 +0000</pubDate>
      <link>https://dev.to/knowthen/introduction-to-phoenix-liveview-240f</link>
      <guid>https://dev.to/knowthen/introduction-to-phoenix-liveview-240f</guid>
      <description>&lt;p&gt;A couple years ago I was at the beginning stages of a new web project, and I was figuring out how I wanted to build the app. I felt like I had a pretty good understanding of what the requirements were, and initially, I was thinking I could build the app as a traditional &lt;strong&gt;MPA (Multi Page App)&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Ok, building MPA's isn't cool or sexy, but it's way simpler than building &lt;strong&gt;SPA's (Single Page Apps)&lt;/strong&gt;, and I'm more productive with MPA's and in my opinion, these kinds of apps are easier to maintain... I mean, if you think about it, the jump from MPA's to SPA's adds a ton of complexity, and having to switch back and forth between a frontend and a backend language is a real cognitive burden.&lt;/p&gt;

&lt;p&gt;Anyway, as I was thinking about how to implement the app, I was stuck on a couple small but important features that would be pretty hard to implement in a MPA, and I was thinking about some of the phase 2 features, and I started to question the viability of implementing this app as a MPA... It felt like a decision I might regret later, so I did what many of us have done, and I just built it as a SPA.&lt;/p&gt;

&lt;p&gt;But honestly, this wasn't an easy decision... In building it as a SPA, I basically took on a bunch of complexity, just to have the &lt;strong&gt;ability to add "rich" features, which for the most part I didn't need&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In hindsight, I don't know if building this app as a SPA was the right choice. It took me longer to implement, and those future features I was worried about, were never added, and every once in a while when I work on this project, npm tells me I'm using a bunch of libraries that have vulnerabilities... so I have to spend a significant amount of time digging into the vulnerabilities, and resolving them, and of course it's a reminder that I should probably be more proactive in maintaining my apps, even when I'm not adding features.&lt;/p&gt;

&lt;p&gt;It would be kind of nice if there was a middle ground between SPA's and MPA's... in other words, it would be nice if there was a way to build web apps with richer features, without having to take on all the complexity associated with SPA's... &lt;em&gt;right?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well, I've got good news, there's a new way to build applications that offer rich, real-time features without adding a ton of complexity.&lt;/p&gt;

&lt;p&gt;Now, the solution I'm referring to is quite novel, and there's a good chance your first impression will be something along the lines of &lt;em&gt;"This seems a little crazy"&lt;/em&gt;...  Those were my first thoughts, but after learning more about it, and using it, I've become a believer.&lt;/p&gt;

&lt;p&gt;So what is the new option I'm referring to?&lt;/p&gt;

&lt;p&gt;It's called &lt;a href="https://github.com/phoenixframework/phoenix_live_view"&gt;Phoenix LiveView&lt;/a&gt;, which is a library that works with the &lt;a href="https://phoenixframework.org/"&gt;Phoenix Web Framework&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you're curious about Phoenix LiveViews, and you want to learn more, you should checkout the screencast I just released (shown below). &lt;/p&gt;

&lt;p&gt;Now, LiveView only works with the Phoenix Web Framework, which is written in &lt;a href="https://elixir-lang.org/"&gt;Elixir&lt;/a&gt;, but you don't need to know Phoenix or Elixir to watch this screencast...  In fact, &lt;strong&gt;I made this video specifically for web developers who don't know Elixir&lt;/strong&gt; (if you do know Elixir, I think you'll still find a lot of value in watching this video).&lt;/p&gt;

&lt;p&gt;Ok, even if you have no intention of using Elixir or Phoenix, you still might want to watch this video, because it truly is a unique solution that I bet you'll find interesting, and I think exposing yourself to new ideas like this, can often lead to other creative solutions.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/U_Pe8Ru06fM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Want to learn more about Elixir &amp;amp; Phoenix?
&lt;/h3&gt;

&lt;p&gt;Checkout my new course: &lt;a href="https://www.knowthen.com/elixir-and-phoenix-for-beginners"&gt;&lt;strong&gt;Elixir &amp;amp; Phoenix for Beginners&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>phoenix</category>
      <category>liveview</category>
      <category>ux</category>
    </item>
  </channel>
</rss>
