<?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: Rodrigo</title>
    <description>The latest articles on DEV Community by Rodrigo (@rgetkor).</description>
    <link>https://dev.to/rgetkor</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%2F707754%2Fe5487f5d-1382-4f17-b684-00581bb5258d.png</url>
      <title>DEV Community: Rodrigo</title>
      <link>https://dev.to/rgetkor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rgetkor"/>
    <language>en</language>
    <item>
      <title>Secure API Keys on the Frontend - Vue JS
</title>
      <dc:creator>Rodrigo</dc:creator>
      <pubDate>Fri, 17 Sep 2021 04:08:27 +0000</pubDate>
      <link>https://dev.to/korconnect/secure-api-keys-on-the-frontend-vue-js-1l21</link>
      <guid>https://dev.to/korconnect/secure-api-keys-on-the-frontend-vue-js-1l21</guid>
      <description>&lt;p&gt;Why are we going to use KOR Connect?&lt;/p&gt;

&lt;p&gt;APIs keys / secrets have been traditionally stored in an application’s backend but this requires control of your own server as well as specialized infrastructure knowledge to set up properly. On CDN hosted, or serverless client side applications it is often not possible to gain access to the server that is hosting the project. If the developer hardcodes the API keys to their frontend anyone is able to access the keys and steal them. When API keys are stolen the malicious agent is able to do whatever they want with the APIs. This could rack up costs for the developer, use all of the allowed calls, or if the APIs are used against the TOS the dev’s credentials may be revoked. The other route that is often suggested to hide API keys for client side applications is to set up serverless functions to store the API keys and act as a proxy for the frontend. The developer could also use CORS to identify the header origin to make sure that only the allowed domains are calling the proxy (so that not anyone is able to call the proxy url from anywhere). This may seem secure but CORS only verifies browser calls and can be easily spoofed or can be called from outside of the browser. A malicious agent could easily run up costs with a bot or have the endpoint shut down as well. KOR Connect has a system that automatically protects against these vulnerabilities as well as allows the developer to integrate any API in the simplest and quickest possible way. &lt;/p&gt;

&lt;p&gt;Now let me walk you through an example!&lt;/p&gt;

&lt;p&gt;I have wanted to create a COVID-19 tracker for sometime; I wanted to create the app in a way where I consume an API but without a backend. In order to do this, I had a couple of options.The approach that initially came to mind was to use public APIs on a static site, but during my planning phase I came across &lt;a href="https://rapidapi.com" rel="noopener noreferrer"&gt;https://rapidapi.com&lt;/a&gt;. Here I found an array of different options for Covid data APIs, the caveat was that the APIs required authentication.&lt;/p&gt;

&lt;p&gt;I could have spun up a small backend and dealt with authentication there but a simple COVID-19 tracker webapp didn’t warrant such efforts.&lt;/p&gt;

&lt;p&gt;In the end I ended up using &lt;a href="https://korconnect.io/" rel="noopener noreferrer"&gt;https://korconnect.io/&lt;/a&gt;, a connection middleware that allows you to connect APIs without a backend. This is how I did it:&lt;/p&gt;

&lt;p&gt;I created an account on &lt;a href="https://korconnect.io/" rel="noopener noreferrer"&gt;https://korconnect.io/&lt;/a&gt;&lt;br&gt;
Also created an account on &lt;a href="https://rapidapi.com/" rel="noopener noreferrer"&gt;https://rapidapi.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, I needed to choose an API to consume. I decided on this one which uses Johns Hopkins public data:&lt;br&gt;
&lt;a href="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%2Ffz2fmsarb10bb8a3zvpz.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffz2fmsarb10bb8a3zvpz.png" alt="https://rapidapi.com/axisbits-axisbits-default/api/covid-19-statistics/"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I started by creating an API connection on KOR Connect by clicking on the “+ Connect API” button:&lt;br&gt;
&lt;a href="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%2Foks4n7ozo0b0bf3yihle.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foks4n7ozo0b0bf3yihle.png" alt="Dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I added the connection details, all of this information was copied directly from RapidAPI. More information about that here: &lt;a href="https://kor-comunity.gitlab.io/kor-connect/adir/GETSTARTED.html" rel="noopener noreferrer"&gt;https://kor-comunity.gitlab.io/kor-connect/adir/GETSTARTED.html&lt;/a&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxhuwytwk08zgfo7agplz.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxhuwytwk08zgfo7agplz.png" alt="Connection Details"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Done! After making the connection I went to the code snippets to see how I would consume the API in my frontend. In my case I wanted to use VueJS to create my tracker so I went to the VueJS snippets section and retrieved the information I needed for the framework.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd7xkwmpzt5cgl8jwwbfv.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd7xkwmpzt5cgl8jwwbfv.png" alt="VueJS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, all good! Now, the tricky part…making the site. I don’t have much experience coding on React or Vue but I found a great video tutorial that walked me through building a COVID-19 tracker.&lt;/p&gt;

&lt;p&gt;Check this excellent tutorial by Traversy Media: &lt;a href="https://www.youtube.com/watch?v=m-MAIpnH9ag" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=m-MAIpnH9ag&lt;/a&gt; (Here is the code for his COVID-19 tracker &lt;a href="https://github.com/bradtraversy/vue-c.." rel="noopener noreferrer"&gt;https://github.com/bradtraversy/vue-c..&lt;/a&gt;.).&lt;/p&gt;

&lt;p&gt;One thing of note, in that tutorial he uses a public API. So I had to figure out how to use the Kor Connect snippet in my code. Thankfully, it was very easy!&lt;/p&gt;

&lt;p&gt;First, let’s take a look at how Kor Connect provides the snippet:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvs4w5di5xj14wb2eyf6l.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvs4w5di5xj14wb2eyf6l.png" alt="Kor Connect Snippet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how I integrated it into my 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiwowxpojt5ulbsdnbrit.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiwowxpojt5ulbsdnbrit.png" alt="Code Implementation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Something to note is how I modified the KOR Connect URL with the paths I received from RapidAPI. For example, to get the summary report I needed to add this to the end of my URL:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/reports/total
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Pay attention to the paths that your API provider gives you and put them at the end of your KOR Connect URL.&lt;/p&gt;

&lt;p&gt;Now, all the calls can be made to the link that KOR Connect provides, KOR Connect will act as a proxy to authenticate as well as send back the API information. Furthermore, thanks to reCaptcha enterprise’s (which is implemented automatically) layers of security several malicious attack vectors are blocked, this enhances KOR Connects security.&lt;/p&gt;

&lt;p&gt;What does the final project look like?&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff2cphqumvaob6kbk30ge.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff2cphqumvaob6kbk30ge.png" alt="Result"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Best of all, for this quick and safe API consumption I don’t need to expose my API token to the public nor do I have to spin up a backend.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>security</category>
      <category>webdev</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
