<?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: Codemy.net</title>
    <description>The latest articles on DEV Community by Codemy.net (@codemy).</description>
    <link>https://dev.to/codemy</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%2Forganization%2Fprofile_image%2F333%2F9fb1dc1c-3817-4a1a-9987-b0cd74c7247e.png</url>
      <title>DEV Community: Codemy.net</title>
      <link>https://dev.to/codemy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codemy"/>
    <language>en</language>
    <item>
      <title>Ruby on Rails API Authentication</title>
      <dc:creator>Zack Siri</dc:creator>
      <pubDate>Tue, 12 Feb 2019 07:14:19 +0000</pubDate>
      <link>https://dev.to/codemy/ruby-on-rails-api-authentication-2374</link>
      <guid>https://dev.to/codemy/ruby-on-rails-api-authentication-2374</guid>
      <description>&lt;p&gt;If you are building any kind of API with Ruby on Rails you are going to have to handle authentication if you want to secure your endpoints. If you're using devise with it's pre-built authentication you'll see that when it comes to managing the Authentication of an API endpoint devise falls slightly short. In this post we will show you some of the options you have with securing your Rails API endpoints and how you can integrate them into devise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simple Token Authentication
&lt;/h2&gt;

&lt;p&gt;If you have a simple requirement where you just want basic authentication via supplying a token to the client then look no further. This gem is as simple as the name itself. You can &lt;a href="https://github.com/gonzalo-bulnes/simple_token_authentication" rel="noopener noreferrer"&gt;check it out here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The way it works is you run a simple command that pretty much generates the migration file for the user model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails g migration add_authentication_token_to_users "authentication_token:string{30}:uniq"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This essentially adds a &lt;code&gt;authentication_token&lt;/code&gt; field yo your user model. You then add a macro to your user model like so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;acts_as_token_authenticatable&lt;/span&gt;
  &lt;span class="c1"&gt;# ...&lt;/span&gt;

&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then you add another macro to your ApplicationController&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;acts_as_token_authentication_handler_for&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;fallback: :none&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then any endpoint inheriting from the ApplicationController will work with token authentication. &lt;/p&gt;

&lt;p&gt;On the client to authenticate with the endpoint the user has to pass the &lt;code&gt;X-User-Email&lt;/code&gt; and &lt;code&gt;X-User-Token&lt;/code&gt; in the header. That's pretty much it for the simple token authentication gem. Since the gem already works with devise all your devise utilities should work great.&lt;/p&gt;

&lt;p&gt;If you are interested in learning more about JWT authentication check out our free episode below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.codemy.net/posts/rails-api-token-authentication-part-1-006/sets/rails-api" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ja5v5f252j3cku0dw83.jpg" alt="Token Authentication Part 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  JWT Authentication with Devise
&lt;/h2&gt;

&lt;p&gt;JSON Web Token is all the rage when it comes to api authentication. This is because it makes life convenient when it comes to securing your API. How? Well If you are building your API for multiple clients, by using JWT you have 1 method of authentication that will work across all platforms whether you are authenticating a client in the browser, a mobile application, or any kind of server side service consuming data from your api. &lt;/p&gt;

&lt;p&gt;It supports a ton of features and allows you to generate a token for the client on the fly without having anything stored in the database, because the token itself contains the session information. You can generate a token and embed any kind of information into it. For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"user_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"exp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1516239022&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gets turned into&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjE1MTYyMzkwMjJ9.UCTyi_gPUNhfeelaWxMTfnPtRtNByDUMxKTRpkyewQI
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a cryptographically secure token generated using a secret key on the server. Which means it can only be decrypted by any party with the secret key. Which means if this secret key gets compromised your authentication token method will be compromised.&lt;/p&gt;

&lt;p&gt;The client then embeds this token in the header usually called &lt;code&gt;Authorization&lt;/code&gt;. Each request needs to be authenticated on the server using this token. Which means the token sent by the client needs to be decoded on the server and the data can be verified on the server side. You can check out more about the basics of JWT in our free video.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.codemy.net/posts/rails-api-json-web-token-part-1-035/sets/rails-api" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiuhrr2qq1z255y0m0r5l.jpg" alt="JSON Web Token Part 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the video we show you how to generate a basic JWT token using the jwt gem. We event show you how to fulling develop an authentication solution using JWT.&lt;/p&gt;

&lt;p&gt;Once you start working with JWT in your Rails API you'll realize that it doesn't work with your existing devise setup. Which is why we recently released 2 episodes showing you how to integrate your JWT solution with devise by creating a custom devise strategy. You can check them out below. They're member's exclusive so you'll need to become a member for $9 / month, however if you just want the code example it's available for free by clicking the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.codemy.net/posts/rails-api-devise-and-jwt-integration-part-1-040/sets/rails-api" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fimverbyyy0tt4e9y23qj.jpg" alt="Devise + JWT Integration Part 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.codemy.net/posts/rails-api-devise-and-jwt-integration-part-2-041/sets/rails-api" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F89xy5z85pr4wmgbpqsde.jpg" alt="Devise + JWT Integration Part 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are building an API with Ruby on Rails and don't know where to start, I would recommend going for JWT. Since JWT is more future proof and there is a standard that you can follow. Having a standard can be useful because you have 1 authentication system that works in many platforms / languages. So if you are building micro-services in multiple languages you can use the libraries for the language of your service and have different services use 1 authentication system that work with one another.&lt;/p&gt;

&lt;p&gt;JWT as a solution can grow as your application grows in complexity. You can start off with a database-less JWT solution and later on add the ability to store the token in the database so you can expire tokens at will.&lt;/p&gt;

&lt;p&gt;On &lt;a href="https://www.codemy.net" rel="noopener noreferrer"&gt;our site&lt;/a&gt; we use JWT for many things, authenticating our users, service-to-service communication, and authenticating video plays. Since we can embed data into the token itself this makes it very flexible for many kinds of things.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>devise</category>
      <category>jwt</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Rails Routes, HTTP Methods and SQL Queries</title>
      <dc:creator>Zack Siri</dc:creator>
      <pubDate>Tue, 29 Jan 2019 12:52:42 +0000</pubDate>
      <link>https://dev.to/codemy/rails-routes-http-methods-and-sql-queries-21ff</link>
      <guid>https://dev.to/codemy/rails-routes-http-methods-and-sql-queries-21ff</guid>
      <description>&lt;p&gt;Learning how the rails routes are generated and how they map to HTTP methods and SQL queries is a foundational piece of knowledge that is missed by many developers when starting out. In this post we will explore some of the basics that will help fill in the gap so that students can understand Rails routes in the least amount of time.&lt;/p&gt;

&lt;p&gt;Rails convention depict that a controller should only have 7 actions most of the time. Generally speaking if you are creating a controller or defining routes and you feel like you need something other than the 7 standard action you should consider creating a new controller.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.codemy.net/rails-routes-http-methods-and-sql-queries/"&gt;In the rest of this post&lt;/a&gt; we uncover how Rails Routes map to HTTP Methods and SQL Queries&lt;/p&gt;

</description>
      <category>rails</category>
      <category>webdev</category>
      <category>learning</category>
    </item>
    <item>
      <title>Ruby Symbols</title>
      <dc:creator>Zack Siri</dc:creator>
      <pubDate>Fri, 18 Jan 2019 08:58:14 +0000</pubDate>
      <link>https://dev.to/codemy/ruby-symbols-5e62</link>
      <guid>https://dev.to/codemy/ruby-symbols-5e62</guid>
      <description>&lt;p&gt;&lt;a href="https://www.codemy.net/posts/rfs-symbols-007/sets/ruby-from-scratch"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aEmX_9Nx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1g74wmiwo9xxk4e78ze5.jpg" alt="Ruby Symbols"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Symbols are immutable data structure in ruby, it can come in handy in many instances. We also explore the difference between ruby's Strings and Symbols &lt;a href="https://www.codemy.net/posts/rfs-symbols-007/sets/ruby-from-scratch"&gt;in this episode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This video is a part of the &lt;a href="https://www.codemy.net/sets/ruby-from-scratch"&gt;Ruby From Scratch&lt;/a&gt; Series on Codemy.net&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>programming</category>
    </item>
    <item>
      <title>Create a Custom Plug</title>
      <dc:creator>Zack Siri</dc:creator>
      <pubDate>Fri, 21 Dec 2018 10:41:45 +0000</pubDate>
      <link>https://dev.to/codemy/create-a-custom-plug-l91</link>
      <guid>https://dev.to/codemy/create-a-custom-plug-l91</guid>
      <description>&lt;p&gt;We show you how to create your own elixir plug in 3 parts. Check out the free code example. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.codemy.net/posts/elixir-custom-plug-part-1-008/sets/elixir-foundation"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CtltoVt5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/r30o8ryhro5jmxt58n0v.jpg" alt="Custom Plug Part 1"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>learning</category>
      <category>video</category>
    </item>
    <item>
      <title>Learn React on Rails</title>
      <dc:creator>Zack Siri</dc:creator>
      <pubDate>Wed, 26 Sep 2018 08:49:00 +0000</pubDate>
      <link>https://dev.to/codemy/learn-react-on-rails-2f62</link>
      <guid>https://dev.to/codemy/learn-react-on-rails-2f62</guid>
      <description>

&lt;p&gt;&lt;a href="https://www.codemy.net/collections/learn-react-on-rails"&gt;React and Ruby on Rails&lt;/a&gt; is a powerful combination. &lt;a href="https://www.codemy.net/collections/learn-react-on-rails"&gt;This collection&lt;/a&gt; is a combination of the React Foundation, Rails API and React Intermediate series. It is organized in sequence of how the invoiced application is created. This is a great way to learn how to build React apps that get their data from a Rails API backend.&lt;/p&gt;


</description>
      <category>react</category>
      <category>rails</category>
      <category>learning</category>
    </item>
    <item>
      <title>Upgrading Legacy Rails App Guide</title>
      <dc:creator>Zack Siri</dc:creator>
      <pubDate>Tue, 11 Sep 2018 12:21:01 +0000</pubDate>
      <link>https://dev.to/codemy/upgrading-legacy-rails-app-guide-28d</link>
      <guid>https://dev.to/codemy/upgrading-legacy-rails-app-guide-28d</guid>
      <description>&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhtkoqswxutfatqxdtc9w.jpg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fhtkoqswxutfatqxdtc9w.jpg" alt="Upgrading Legacy Rails App Part 1"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.codemy.net/posts/rails-upgrading-a-legacy-rails-app-part-1" rel="noopener noreferrer"&gt;Upgrading a Legacy Rails App Part 1&lt;/a&gt; - Upgrading a legacy rails app is a chore for every rails developer. Knowing the right strategy can save you a lot of time. We'll be showing you exactly how to go about it in this episode!&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0vru3sg62jjt8olnm2w7.jpg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0vru3sg62jjt8olnm2w7.jpg" alt="Upgrading Legacy Rails App Part 2"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.codemy.net/posts/rails-upgrading-a-legacy-rails-app-part-2" rel="noopener noreferrer"&gt;Upgrading a Legacy Rails App Part 2&lt;/a&gt; - We continue the upgrade process from the previous episode. Now that our application is running on the stable version of 4.2.10 . We can start the process of upgrading to 5.2.1 . We will use the railsdiff.org extensively to guide us through the upgrade process.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxgclgg3hvmmfh5g2mksa.jpg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxgclgg3hvmmfh5g2mksa.jpg" alt="Upgrading Legacy Rails App Part 3"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.codemy.net/posts/rails-upgrading-a-legacy-rails-app-part-3" rel="noopener noreferrer"&gt;Upgrading a Legacy Rails App Part 3&lt;/a&gt; - We finalize the upgrade process by patching up a few files. Once all the changes are in place we should be able to run bundle update rails&lt;/p&gt;

</description>
      <category>rails</category>
      <category>video</category>
    </item>
  </channel>
</rss>
