<?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 Gui Íscaro on Medium]]></title>
        <description><![CDATA[Stories by Gui Íscaro on Medium]]></description>
        <link>https://medium.com/@cabelitostos?source=rss-ddcb3c1f2e9e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BpfpuC-njrqBS3_NysZBJg.jpeg</url>
            <title>Stories by Gui Íscaro on Medium</title>
            <link>https://medium.com/@cabelitostos?source=rss-ddcb3c1f2e9e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 09:26:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cabelitostos/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[Keycloak passwordless authentication]]></title>
            <link>https://medium.com/profusion-engineering/keycloak-passwordless-authentication-550ca095c0bf?source=rss-ddcb3c1f2e9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/550ca095c0bf</guid>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[otp-verification]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[passwordless]]></category>
            <dc:creator><![CDATA[Gui Íscaro]]></dc:creator>
            <pubDate>Tue, 03 Nov 2020 15:42:04 GMT</pubDate>
            <atom:updated>2023-10-09T12:27:34.337Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*GAyd0ObHxmDMbiOuIThNhA.png" /></figure><p>Today, more and more services are migrating to the cloud, which requires us to have an infinite amount of accounts and, of course, passwords. Though many apps were created to help users store and generate safe passwords, they still might not be as secure as one-time passwords.</p><p>Although many identity and access managers like <a href="https://auth0.com/passwordless/#sms">Auth0</a> and <a href="https://www.okta.com/passwordless-authentication/">Okta</a> provide support for passwordless authentication, one might eliminate them as a valid option due to their costs or other technical limitations.</p><h3>Enter Keycloak</h3><p><a href="https://www.keycloak.org/">Keycloak</a> is an open-source software mainly developed by <a href="https://www.redhat.com/en">RedHat</a> that is able to handle both authentication and authorization, while still being highly customisable via plugins or via its admin console. Although it does not support passwordless authentication out-of-the-box, it’s fairly easy to add it without a single line of code. The following sections of this article demonstrates how you can configure Keycloak to authenticate users using One-time password (OTP) apps like Google Authenticator or Authy.</p><blockquote><em>This article assumes that you already have a Keycloak instance up and running and there is at least one realm created with enabled registration via web forms.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S81K9nrz-oaKrE4uEG7P0g.png" /><figcaption>Keycloak instance with custom realm and registration on.</figcaption></figure><h3>Configuring Browser Auth Flow</h3><p>First, we need to configure the login flow to stop requesting a password, and instead, request an OTP code from the user. To do this, the following steps are needed:</p><ul><li>Select the desired realm or create a new one;</li><li>Select the Authentication Menu on the left panel;</li><li>On the Flows Tab, click on the browser flow menu and then click Duplicate;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QdWsDnby1001e9EkqVG0CQ.png" /></figure><ul><li>A modal will open, name the new flow Otp-browser-auth and then click onDuplicate;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1sENuHU19EAgfefnOJD8Q.png" /></figure><ul><li>The newly created Browser flow will be opened;</li><li>Delete all steps under Otp-browser-auth forms;</li><li>Add a Username Formstep for Otp-browser-auth forms;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jE-HiKXUr3XqTTlNwOZ28A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OSpGP87blCCoq_1ei0pxtQ.png" /></figure><ul><li>Now do the same process, but add a OTP Form step for Otp-browser-auth forms;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x73jQ02ttfcW02u_Nc5Dmg.png" /></figure><ul><li>Make both Otp-browser-auth forms and OTP Forms Required;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6ZnLxNC6La983mBhCrTsQ.png" /></figure><h3>Configuring the Registration Flow</h3><p>The registration flow must be changed to ask for an OTP code instead of a password, since the latter won’t be used anymore. To create a new registration flow, follow these steps:</p><ul><li>Select the desired realm;</li><li>Select the Authentication Menu on the left panel;</li><li>On the Flows Tab create a copy for the Registration flow and name it Otp-Registration-Form (same process we did it for Otp-browser-auth);</li><li>Mark the Password Validation step as Disabled ;</li><li>Click on Add Stepat the top of the page, add a OTP Form step and mark it as Required;</li><li>Your registration flow should look like this</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8o86ftTVAEx4k6MjadURXQ.png" /></figure><h3>Enabling the new flows</h3><p>In order to enable the new flows, we need to tell Keycloak to use them by following these steps:</p><ul><li>Select the desired realm;</li><li>Select the Authentication Menu on the left panel;</li><li>Click on the Otp-browser-auth menu and then click on Bind flow, then select Browser Flowand hit Save;</li><li>Click on the Otp-Registration-Form menu and then click on Bind flow, then select Registration Flowand hit Save;</li></ul><p>After the steps above, Keycloak’s bindings should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Be5lofutP5BJ2YAp_RN8aQ.png" /></figure><h3>Testing</h3><p>Now that Keycloak is configured, we can test everything. Let’s start by initiating an auth flow for a client in our realm, registering a user and logging in.</p><blockquote><em>You can do that by going to </em><a href="http://localhost:8080/realms/Otp-realm/account/#/">http://&lt;your-keycloack-domain&gt;:&lt;port&gt;/realms/&lt;your-realm&gt;/account/#/</a> and clicking on “Sign In”</blockquote><p>Once the flow is started, Keycloak will send us to the login page that should look like the image below. Notice that there’s no password field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FlW_Ax83kXCL5qKzK-T_GQ.png" /></figure><p>Since there are no users, let’s register one via the Register link which will lead us to the registration form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sxlbqRZt58HLTCoT_LXKQw.png" /></figure><p>Once the basic info is provided and the Register button is clicked, Keycloak will ask us to register the OTP seed using an app like Google Authenticator or Authy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNtmLpheC4Lbokh_lDG8QQ.png" /></figure><p>After that, the user is ready and we can log-in. Start by going back to the login page and fill the user’s email and click on Login.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*toYdKiFQZaUTa288UrxJHg.png" /></figure><p>If the usernameor email is valid and exists on the database, Keycloak will ask for an OTP which should be obtained via the Google Authenticator or Authy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJ_Fj5Xd6vZTZXduVMJKdg.png" /></figure><p>And <em>voilà</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=550ca095c0bf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/profusion-engineering/keycloak-passwordless-authentication-550ca095c0bf">Keycloak passwordless authentication</a> was originally published in <a href="https://medium.com/profusion-engineering">ProFUSION Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[File Uploads, GraphQL and Apollo Federation]]></title>
            <link>https://medium.com/profusion-engineering/file-uploads-graphql-and-apollo-federation-c5a878707f4c?source=rss-ddcb3c1f2e9e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5a878707f4c</guid>
            <category><![CDATA[apollo-server]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[apollo-federation]]></category>
            <dc:creator><![CDATA[Gui Íscaro]]></dc:creator>
            <pubDate>Wed, 09 Sep 2020 23:24:01 GMT</pubDate>
            <atom:updated>2020-09-09T23:24:01.077Z</atom:updated>
            <content:encoded><![CDATA[<p>With the rise of <a href="https://graphql.org/">GraphQL</a>, every day more and more APIs are written using this new technology in favor of <a href="https://en.wikipedia.org/wiki/Representational_state_transfer">REST</a> APIs.</p><p>For those who have no idea what’s GraphQL, please stick with me. However if you are already familiar with it, please skip to this <a href="#d7c1">section</a>.</p><h3>What’s GraphQL?</h3><p>GraphQL is a query language for an API and server-runtime for executing these queries. So when creating a new GraphQL service, one must explicitly define a schema that serves as a contract between the service itself and all its clients.</p><p>As an example, let’s imagine that we want to create an API, that one can use to obtain information about a user. The schema would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/230caa4f4f963d1de2a923551c84c977/href">https://medium.com/media/230caa4f4f963d1de2a923551c84c977/href</a></iframe><p>As we can see, it’s pretty much straight forward to create a schema that holds basic information about a user. You might be wondering what’s the <em>Query</em> and the <em>Mutation</em> type that we introduced.</p><p>The <em>Mutation</em> type is used to perform side-effects operation on the server-side, in our case, change the user’s name. For those coming from REST API, any operation that is made using PUT, POST or DELETE should be in a mutation.</p><p>The <em>Query</em> type is used strictly for fetching data, you can compare this type to any GET request to a REST API. This type should <strong>not</strong> cause side-effects on the server-side.</p><p><strong>PRO-TIP</strong>: The “!” after the type name, means that null is <strong>not</strong> allowed. If, for some reason, the user query returns a null the server will yell at you.</p><p>With the schema defined a client can request the user’s information as well as changing their name. GraphQL queries resembles the schema itself and are very descriptive about what they are doing. For example, if one wants to obtain the information about the user, a query operation can be request to the server by sending the following structure:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9aabb0c9380ca040a062406c7ce483c6/href">https://medium.com/media/9aabb0c9380ca040a062406c7ce483c6/href</a></iframe><p>The response would be the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7535980915f96b27ecbf2e9296ff523f/href">https://medium.com/media/7535980915f96b27ecbf2e9296ff523f/href</a></iframe><p>The same idea can be applied when doing a mutation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ec9c90d2812ab88ca8a3411e1f4da67/href">https://medium.com/media/4ec9c90d2812ab88ca8a3411e1f4da67/href</a></iframe><p>The response would be the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4f1ee9772482011aea50a3bb64dad81/href">https://medium.com/media/e4f1ee9772482011aea50a3bb64dad81/href</a></iframe><p>GraphQL is a complex topic and I’m not going to cover everything about it in this post, if you wish to learn more, please visit the official documentation. Also sandbox can be found in <a href="https://codesandbox.io/s/keen-surf-6o8ou?file=/index.js">here</a>, where you can play with the schema and do your own queries and mutations.</p><h3>File Uploads</h3><p>Now that we know a little bit about GraphQL, we can jump to the important question: How can I uploads files using my GraphQL API?</p><p>If you remember the old days when basically all APIs were based on REST we could simply use a <em>multipart/form-data</em> upload and move on. Something like this when using <a href="https://curl.haxx.se/">cURL</a>:</p><pre>$ curl -F ‘img=@/my/path/img.png’ <a href="http://localhost/upload">http://</a>my-api.com/photo</pre><p>However this is not the case in GraphQL. If you remember the <em>spec, </em>GraphQL does not define the transport method — which means that my GraphQL API can be powered by smoke signals if needed 🌚.</p><p>Not having a standard way about how the data is transferred between a server and a client makes a little difficult to add to the <em>spec</em> how binary files should be transported, because it’s beyond its scope.</p><p>Fortunately the <em>de facto</em> standard for GraphQL is our good old friend HTTP and some folks even created a spec for it, which can be found in <a href="https://github.com/jaydenseric/graphql-multipart-request-spec">here</a>.</p><p>The idea resembles what it was done with a REST API, the binary data will be sent using <em>multipart/form-data </em>along with the query/mutation request.</p><p>Going back to our user API, if we want to add mutation to add the user’s photo, it could be changed to look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ace0403a79a65eadfcfb9009fe389bb0/href">https://medium.com/media/ace0403a79a65eadfcfb9009fe389bb0/href</a></iframe><p>And to send a request one could do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fe7ef960568ef966cde1b63b052001b/href">https://medium.com/media/0fe7ef960568ef966cde1b63b052001b/href</a></iframe><p>If you pay attention to the cURL request, you’ll see that we are doing a <em>multipart/form-data </em>request and instructing cURL that file is located at key <em>0</em> and it belongs to <em>variables.photo. </em>If more files were needed, this map value would grow to accommodate another file the request would look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f812b2c1049cce8316fcee51407a8935/href">https://medium.com/media/f812b2c1049cce8316fcee51407a8935/href</a></iframe><p>Fortunately our friends at <a href="https://www.apollographql.com/">Apollo</a> already supports basic file uploads by default on ApolloServer. On this <a href="https://codesandbox.io/s/keen-surf-6o8ou?file=/index.js">link</a> you can find the implementation and also send requests to it, directly on your computer. But remember to keep the sandbox open!</p><p>You can use the following test collection to play with:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd90c49ee562c5498015e53d567c87ca/href">https://medium.com/media/fd90c49ee562c5498015e53d567c87ca/href</a></iframe><h3>Apollo Federation &amp; File upload</h3><p>Great, now that we know how file uploads works on GraphQL we can talk a little bit about Apollo Federation and its relation with uploads. In case you have no idea what Apollo federation is, please check this <a href="https://www.apollographql.com/docs/apollo-server/federation/introduction/">link</a>.</p><p>Given the Apollo Federation architecture, all requests you make first hit the Apollo Gateway and then the gateway itself will decide to which micro-service the GraphQL request will be delivered to. I made some changes to our <a href="https://codesandbox.io/s/apollo-federation-upload-v5um0">sandbox</a>.</p><p>Now we have the following architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/169/1*9-8lCWYitoQQ5HQCSD1h5w.png" /></figure><p>Using this new architecture let’s try to upload a photo and see what happens:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0378e9f105d0697c6f60ada5baaf5f71/href">https://medium.com/media/0378e9f105d0697c6f60ada5baaf5f71/href</a></iframe><p>As we can see the <em>createReadStream()</em> function is invalid, which means that our file was NOT received by the user micro service. Having this in mind, let’s inspect the gateway itself and see if it’s receiving the file. In order to do this, I created a <a href="https://www.apollographql.com/docs/apollo-server/api/apollo-gateway/#remotegraphqldatasource">RemoteGraphQLDataSource</a> just for inspection.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/393712310955a0217563bf47f0099690/href">https://medium.com/media/393712310955a0217563bf47f0099690/href</a></iframe><p>If a run the file upload again I can see the following output on the server’s console:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa8b569b9f4740420e23b6ff2267a6ef/href">https://medium.com/media/aa8b569b9f4740420e23b6ff2267a6ef/href</a></iframe><p>Since the file is being sent the gateway itself, maybe there’s a way to send it to the user’s micro-service, right?</p><h3>Enter @profusion/apollo-federation-upload</h3><p>Here at <a href="https://profusion.mobi/">Profusion</a> we developed a <a href="https://www.npmjs.com/package/@profusion/apollo-federation-upload">npm package</a> which handles file uploads with federation by simple adding a RemoteGraphQLDataSource to Apollo’s Gateway.</p><p>Its usage is quite simple, when creating a gateway you must do the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebb54238ad5374e4ee96c6dc319474b1/href">https://medium.com/media/ebb54238ad5374e4ee96c6dc319474b1/href</a></iframe><p>And that’s it!</p><p>This package supports arrays, inputs and simple uploads. Going back to our <a href="https://codesandbox.io/s/apollo-federation-upload-profusion-gdgs4">sandbox</a>, let’s try to upload a file using this new package.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20a77d56d7ed6c15254703a4b4776e78/href">https://medium.com/media/20a77d56d7ed6c15254703a4b4776e78/href</a></iframe><p>As we can see, the mutation works as expected and the image was correctly uploaded to the user micro-service.</p><p>The implementation of this package is quite simple and can be expressed with the following diagram (or you can check the <a href="https://github.com/profusion/apollo-federation-file-upload/blob/master/lib/FileUploadDataSource.ts#L20">code</a>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*ZQzEjGm_ZmB7VoWDHDWOWQ.png" /></figure><p>It’s important to note that this approach is not recommended in services that have a high amount of file uploads, since all files are uploaded to the gateway and then to the micro-service itself. One possible solution would be by letting the API user upload the file directly to an upload service that is not behind the gateway by using some kind of signed URL. I’ll cover this topic in the future with another post. In the mean time you can use our package 😬.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5a878707f4c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/profusion-engineering/file-uploads-graphql-and-apollo-federation-c5a878707f4c">File Uploads, GraphQL and Apollo Federation</a> was originally published in <a href="https://medium.com/profusion-engineering">ProFUSION Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>