<?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 Jimmy Shiau on Medium]]></title>
        <description><![CDATA[Stories by Jimmy Shiau on Medium]]></description>
        <link>https://medium.com/@JimmyShiau?source=rss-e65003ad0252------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ROYCeHqwZaXPMMEF.jpg</url>
            <title>Stories by Jimmy Shiau on Medium</title>
            <link>https://medium.com/@JimmyShiau?source=rss-e65003ad0252------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 13:28:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@JimmyShiau/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[Be a Hero: Create Your Own App with Quire API]]></title>
            <link>https://medium.com/quire-you/be-a-hero-create-your-own-app-with-quire-api-99d19952c3be?source=rss-e65003ad0252------2</link>
            <guid isPermaLink="false">https://medium.com/p/99d19952c3be</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Jimmy Shiau]]></dc:creator>
            <pubDate>Tue, 01 Oct 2019 11:58:07 GMT</pubDate>
            <atom:updated>2019-10-02T04:47:38.382Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Quire API" src="https://cdn-images-1.medium.com/max/1024/0*r_avYiHGXijOhAjA.png" /></figure><p>We are happy to announce the release of version 1.0.0 of our OpenAPI, Quire uses <a href="http://oauth.net/documentation/">OAuth 2.0</a> to authenticate requests between your app and your users. With OAuth, users can give you access to their Quire content without giving up their passwords.</p><p>This means that a user could authorize an app to access data or make changes to their Quire account and services that are exposed by the Quire API. For example, an app could create or delete tasks, post a comment, or alter an assignee, due, tags.</p><h3>OAuth Application Setup</h3><p>In order to use Quire API, you’ll need to create an Oauth app.</p><h3>Create your Quire oauth app</h3><p>You’ll need to be logged in to your Quire account to create an app.</p><ol><li>Go to the Quire <a href="https://quire.io/apps/dev">developer app console</a> and click on the <strong>Create new app</strong> button.</li></ol><figure><img alt="Quire developer app console" src="https://cdn-images-1.medium.com/max/960/0*N1qEBSlG6A0GCS5S.png" /></figure><p>2. Choose the Quire Organization that your app belongs to, the organization members can view/edit all apps belongs to the selected organization.</p><figure><img alt="Quire Open API" src="https://cdn-images-1.medium.com/max/960/0*VmUWrU-SuJk0wPmA.png" /></figure><p>3. Give your application a name and Redirect URL, we will discuss the role of the Redirect URL later. For now you can supply the following URL:</p><p><a href="http://localhost:3000/callback">http://localhost:3000/callback</a></p><p>4. Click the <strong>Create new app</strong> button, your newly created OAuth application will be presented on the developer console page, allowing you to further configure it.</p><figure><img alt="Quire app" src="https://cdn-images-1.medium.com/max/960/0*rCf3YpKD5bLlualZ.png" /></figure><p>In summary, you should have these three bits of information:</p><ul><li><strong>Development Client ID:</strong> :wJoMEodI4fSSR54pfNwIuIzLnaJ</li><li><strong>Development Client Secret:</strong> eb8faf4nyd1wbeconw060e9ejui8zg6w8p1hyoex</li><li><strong>Callback URL:</strong> <a href="http://localhost:3000/callback">http://localhost:3000/callback</a></li></ul><figure><img alt="OpenAPI" src="https://cdn-images-1.medium.com/max/960/0*aXcSv7q431BcjdmS.png" /></figure><h3>Setup Your Development Environment</h3><h3>Step 1. Configure Your App</h3><p>Host your application configuration information in you app.</p><pre><strong>const</strong> clientId = &#39;:wJoMEodI4fSSR54pfNwIuIzLnaJ&#39;;<br><strong>const</strong> clientSecret = &#39;eb8faf4nyd1wbeconw060e9ejui8zg6w8p1hyoex&#39;;<br><strong>const</strong> redirectURI = &#39;http://localhost:3000/callback&#39;;<br>  <br><strong>const</strong> authorizationUrl = &#39;https://quire.io/oauth&#39;;<br><strong>const</strong> tokenUrl = &#39;https://quire.io/oauth/token&#39;;<br><strong>const</strong> apiUrl = &#39;https://quire.io/api&#39;;</pre><h3>Step 2. Redirect User to Authorize App on Quire</h3><p>Generate an authorization url that you will redirect your users to Quire’s OAuth endpoint URI. This will show a web page where logged in Quire users can authorize your application to access their content.</p><p>Sample URL:</p><pre>https://quire.io/oauth?client_id=your-client-ID&amp; redirect_uri =your-redirect-uri</pre><p>An authorization link view example might look like:</p><pre><strong>var</strong> http = require(&#39;http&#39;);<br><strong>var</strong> url = require(&#39;url&#39;);<br><strong>var</strong> server = http.createServer(<strong>function</strong> (req, res) { <br>    <strong>var</strong> uri = url.parse(req.url, <strong>true</strong>);<br>    <strong>if</strong> (uri.pathname == &#39;/&#39;) {        <br>        <em>//..    </em><br>    } <strong>else</strong> <strong>if</strong> (uri.pathname == &quot;/install&quot;) {<br>        <strong>var</strong> authUrl = authorizationUrl <br>            + &#39;?client_id=&#39; + clientId <br>            + &#39;&amp;redirect_uri=&#39; + encodeURIComponent(redirectURI);<br>        res.writeHead(200, { &#39;Content-Type&#39;: &#39;text/html&#39; });<br>        res.write(<br>             &#39;&lt;html&gt;&lt;body&gt;&#39; <br>            + &#39;&lt;a href=&quot;&#39; + authUrl + &#39;&quot;&gt;Connect Quire&lt;/a&gt;&#39; <br>         + &#39;&lt;/body&gt;&lt;/html&gt;&#39;);<br>        res.end();<br><br>    } <strong>else</strong> <strong>if</strong> (uri.pathname == &quot;/callback&quot;) {<br>        <em>//...</em><br>    }<br>});<br>server.listen(3000);</pre><p>The state parameter is a random string used to prevent Cross-Site Request Forgery (CSRF) attacks. You should randomly generate a character string. It will be passed back to your app, unchanged, in Step 3. Your application should validate this value. Though it is optional, we strongly recommend including this parameter.</p><p>Sample URL:</p><pre>https://quire.io/oauth?client_id=your-client-ID&amp;redirect_uri=your-redirect-uri&amp;state=lpcl9v94z</pre><h3>Step 3. Handle the OAuth 2.0 server response</h3><p>The OAuth 2.0 server responds to your application’s access request by using the URL specified in the redirect_uri.</p><p>If the user approves the access request, then the response contains an authorization code. If the user does not approve the request, the response contains an error message. The authorization code or error message that is returned to the web server appears on the query string, as shown below:</p><p><strong>An error response:</strong></p><pre><a href="http://localhost:3000/callback?error=access_denied">http://localhost:3000/callback?error=access_denied</a></pre><p><strong>An authorization code response:</strong></p><pre><a href="http://localhost:3000/callback?code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7">http://localhost:3000/callback?code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7</a></pre><p><strong>A callback example might look like:</strong></p><pre><em>//...</em><br>} <strong>else</strong> <strong>if</strong> (uri.pathname == &quot;/callback&quot;) {<br>   <strong>var</strong> result = uri.query;<br>   <strong>var</strong> message = &#39;Auth fail&#39;;<br>   <strong>if</strong> (result[&quot;error_description&quot;] != <strong>null</strong>) {<br>       message = result[&quot;error_description&quot;];<br>       <strong>if</strong> (result[&quot;error&quot;] == &#39;access_denied&#39;) {<br>           <em>//display reject message</em><br>       }<br>       messageView(res, message);<br>   } <strong>else</strong> <strong>if</strong> (result[&quot;code&quot;] != <strong>null</strong>) {<br>       <strong>return</strong> exchangeAccessToken(result[&quot;code&quot;])<br>       .then(<strong>function</strong>(data) {<br>            <strong>var</strong> token = data[&#39;access_token&#39;];<br>            message = token != <strong>null</strong> ? &#39;Success&#39;: &#39;Fail&#39;;<br>            messageView(res, message);<br>        });<br>   }<br>}</pre><p>When the user is redirected back to your application redirect_uri, a code and state parameter will also be present in the query-string parameters. The state is your CSRF anti-forgery token to validate the request.</p><p>Extract the code and state from the query string parameters. The state may be validated at this point.</p><p><strong>A validate example might look like:</strong></p><pre>} <strong>else</strong> <strong>if</strong> (result[&quot;code&quot;] != <strong>null</strong>) {<br>    <strong>if</strong> (result[&quot;state&quot;] != stateFromSession(res))<br>        <strong>return</strong> messageView(res, &#39;invalid state&#39;);<br>            <br>    <strong>return</strong> exchangeAccessToken(result[&quot;code&quot;])<br>    .then(<strong>function</strong>(data) {<br>         <strong>var</strong> token = data[&#39;access_token&#39;];<br>         message = token != <strong>null</strong> ? &#39;Success&#39;: &#39;Fail&#39;;<br>         messageView(res, message);<br>     });<br>}</pre><h3>Step 4. Exchange authorization code for access token</h3><p>Your application needs to make a POST call to the token endpoint with the extracted authorization code and the request parameters in the below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*L8DzT756iD7KJK6yFjaVqw.png" /></figure><p><strong>A request an access token example might look like this:</strong></p><pre><strong>var</strong> request = require(&#39;request&#39;);<br><strong>function</strong> exchangeAccessToken(code) {<br>    <strong>return</strong> <strong>new</strong> Promise(<strong>function</strong>(resolve, reject){<br>        request.post({<br>            url: tokenUrl, <br>            form: {<br>              grant_type: &#39;authorization_code&#39;,<br>              code: code,<br>              client_id: clientId,<br>              client_secret: clientSecret<br>            }<br>          }, <br>          <strong>function</strong> (error, httpResponse, body) {<br>            <strong>if</strong> (error) {<br>              <strong>return</strong> reject(error);<br>            }<br>            resolve(JSON.parse(body))<br>          });<br>    });<br>}</pre><p>The access token you receive in response will be a JSON format.</p><p><strong>Example Response:</strong></p><pre>{ <br>  &quot;access_token&quot;:&quot;ACCESS_TOKEN&quot;, <br>  &quot;token_type&quot;: &quot;bearer&quot;, <br>  &quot;expires_in&quot;:2592000, <br>  &quot;refresh_token&quot;:&quot;REFRESH_TOKEN&quot;<br>}</pre><p>The token should be kept carefully and permanently since you need it to access every Quire API.</p><h3>Make calls to the API using the access token</h3><p>Your app now has an access token that it can be used to make API calls on user’s behalf.</p><h3>Call the API</h3><p>Make the API call passing the access token as a bearer token in the header of the request.</p><p><strong>An api call example might look like:</strong></p><pre><strong>function</strong> getCurrentUser(token) {<br>    <strong>return</strong> <strong>new</strong> Promise(<strong>function</strong>(resolve, reject){<br>        request.get({<br>            url: apiUrl + &#39;/user/id/me&#39;, <br>            headers: {<br>              &quot;Authorization&quot;: &quot;Bearer &quot; + token<br>            }<br>          }, <br>          <strong>function</strong> (error, httpResponse, body) {<br>            <strong>if</strong> (error) {<br>              <strong>return</strong> reject(error);<br>            }<br>            resolve(JSON.parse(body))<br>          });<br>    });<br>}</pre><p><strong>Example Response:</strong></p><pre>{<br>  &quot;email&quot;: &quot;john@gmail.cc&quot;,<br>  &quot;website&quot;: &quot;https://coolwebsites.com&quot;,<br>  &quot;id&quot;: &quot;My_ID&quot;,<br>  &quot;description&quot;: &quot;This is *cool*!&quot;,<br>  &quot;url&quot;: &quot;https://quire.io/u/My_ID&quot;,<br>  &quot;nameText&quot;: &quot;My Name&quot;,<br>  &quot;nameHtml&quot;: &quot;My Name&quot;,<br>  &quot;descriptionText&quot;: &quot;This is cool!&quot;,<br>  &quot;descriptionHtml&quot;: &quot;This is &lt;i&gt;cool&lt;/i&gt;!&quot;,<br>  &quot;image&quot;: &quot;https://quire.s3.amazonaws.com/oid/image.jpg&quot;,<br>  &quot;iconColor&quot;: &quot;37&quot;,<br>  &quot;name&quot;: &quot;My Name&quot;,<br>  &quot;oid&quot;: &quot;Dyh2YkFcu9uLgLFIeN1kB4Ld&quot;<br>}</pre><h3>Refreshing Tokens</h3><p>An access token intentionally is meant for short-term use only. This is an important security mechanism of OAuth 2.0. When using the Authorization Code Grant Flow, the access tokens have an one-hour lifetime by default.</p><p>When an access token expires, an HTTP 401 error will be returned:</p><pre>{ <br>  code: 401, <br>  message: &#39;Invalid or expired token.&#39; <br>}<br><br>Your application will need to refresh the access token. <br><strong>function</strong> refreshToken(refreshToken) {<br>    <strong>return</strong> <strong>new</strong> Promise(<strong>function</strong>(resolve, reject){<br>        request.post({<br>            url: tokenUrl, <br>            form: {<br>              grant_type: &#39;refresh_token&#39;,<br>              refresh_token: refreshToken,<br>              client_id: clientId,<br>              client_secret: clientSecret<br>            }<br>          }, <br>          <strong>function</strong> (error, httpResponse, body) {<br>            <strong>if</strong> (error) {<br>              <strong>return</strong> reject(error);<br>            }<br>            resolve(JSON.parse(body))<br>          });<br>    });<br>}</pre><p>Alternatively, your application could redirect the user to the authentication flow.</p><p>We hope by now you already know how to use Quire API! We can’t wait to see the amazing apps that you will build for Quire! 😍</p><p><em>Originally published at </em><a href="https://quire.io/blog/p/Create-Your-Quire-App-with-Quire-API.html"><em>https://quire.io</em></a><em> on October 1, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99d19952c3be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/quire-you/be-a-hero-create-your-own-app-with-quire-api-99d19952c3be">Be a Hero: Create Your Own App with Quire API</a> was originally published in <a href="https://medium.com/quire-you">Quire &amp; You</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>