Jekyll2019-10-31T21:39:03+00:00https://pcjdev.github.io/feed.xmlpcjdev.github.ioThe personal blog of a software engineer passionate about programming, clean code, security and open source.
pcjdevAn Introduction to OAuth 2.02019-07-04T00:00:00+00:002019-07-04T00:00:00+00:00https://pcjdev.github.io/security/2019/07/04/an-introduction-to-oauth-2.0<p>OAuth 2.0 is an open standard for authorization, published as <a href="https://tools.ietf.org/html/rfc6749">RFC 6749</a> and <a href="https://tools.ietf.org/html/rfc6750">RFC 6750</a> in October 2012.</p>
<p>OAuth 2.0 enables a third-party application (<strong>client</strong>) to obtain limited access (via an <strong>access token</strong>) to an HTTP service (<strong>resource</strong>), either on behalf of an end-user (<strong>resource owner</strong>) or by allowing the application to obtain access on its own behalf. This specification replaces and obsoletes the OAuth 1.0 protocol.</p>
<h1 id="roles">Roles</h1>
<p>OAuth defines four <em>roles</em>:</p>
<ul>
<li><strong>resource owner</strong> (eg. the end-user)</li>
<li><strong>resource server</strong> (the server hosting the protected resources, capable of accepting and responding to protected resource requests using access tokens)</li>
<li><strong>client</strong> (the application making protected resource requests on behalf of the resource owner)</li>
<li><strong>authorization server</strong> (the server issuing access tokens to the client after successfully authenticating the resource owner and obtaining authorization)</li>
</ul>
<h1 id="obtaining-authorization">Obtaining Authorization</h1>
<p>To request an <strong>access token</strong>, the <strong>client</strong> obtains authorization from the <strong>resource owner</strong>. The authorization is expressed in the form of an <strong>authorization grant</strong>, which the <strong>client</strong> uses to request the <strong>access token</strong>.</p>
<p>OAuth defines four <em>grant types</em> (plus and extension mechanism for defining additional grant types):</p>
<ul>
<li><strong>authorization code</strong></li>
<li><strong>resource owner password credentials</strong></li>
<li><strong>client credentials</strong></li>
<li><strong>implicit</strong></li>
</ul>
<p>The <strong>authorization code grant</strong> is the most used type, for apps running on a web server, browser-based and mobile apps. For other use cases, see <a href="https://auth0.com/docs/api-auth/which-oauth-flow-to-use">here</a> a decision tree about which flow to use.</p>
<p>The <strong>authorization code grant</strong> type is used to obtain both <strong>access tokens</strong> and <strong>refresh tokens</strong> and is optimized for confidential clients. Since this is a redirection-based flow, the client must be capable of interacting with the <strong>resource owner</strong>’s <strong>user-agent</strong> (typically a web browser) and capable of receiving incoming requests (via redirection) from the <strong>authorization server</strong>.</p>
<p><img src="https://www.websequencediagrams.com/cgi-bin/cdraw?lz=dGl0bGUgQXV0aG9yaXphdGlvbiBDb2RlIEdyYW50IEZsb3cKCnBhcnRpY2lwYW50ICJSZXNvdXJjZSBPd25lciIgYXMgUk8AFQ5DbGllbnQAFgVDAC8OAFsOU2VydgA8B0FTAE8XABkLUlMKCkMtPitBUzoAgR4UUmVxdWVzdApSTy0-QVM6IExvZ2luICYgQ29uc2VudApBUy0tPj4tQwAmF3Nwb25zZQBYCUV4Y2hhbmdlAIIIBmZvciBBY2Nlc3MgVG9rZW4AQQwADAsgWysgUmVmcmVzaAAiBl0KbG9vcACBMQVSUzogAIIzCQCBJQcgd2l0aABLDlIAgR0JACILAIEWBgAoBkRhdGEKZW5kCg&s=modern-blue" alt="Authorization Code Grant Flow" /></p>
<h1 id="openid-connect">OpenID Connect</h1>
<p>OAuth 2.0 describes patterns for granting authorization but does not define how to actually perform authentication. One interesting and useful extension of OAuth 2.0 is the <strong>OpenID Connect</strong> protocol.</p>
<p><a href="http://openid.net/connect/">OpenID Connect</a> 1.0 is a simple identity layer on top of the OAuth 2.0 protocol. It allows <strong>clients</strong> to verify the identity of the <strong>end-user</strong> based on the authentication performed by an <strong>authorization server</strong>, as well as to obtain basic profile information about the <strong>end-user</strong> in an interoperable and REST-like manner.</p>
<h1 id="reference">Reference</h1>
<ul>
<li><a href="https://oauth.net/2/">OAuth 2.0 | oauth.net</a></li>
<li><a href="https://tools.ietf.org/html/rfc6749">RFC 6749 - The OAuth 2.0 Authorization Framework</a></li>
<li><a href="https://tools.ietf.org/html/rfc6750">RFC 6750 - The OAuth 2.0 Authorization Framework: Bearer Token Usage</a></li>
<li><a href="https://aaronparecki.com/oauth-2-simplified/">OAuth 2.0 Simplified | Aaron Parecki</a></li>
<li><a href="https://auth0.com/docs/protocols/oauth2">OAuth 2.0 Authorization Framework | Auth0 Docs</a></li>
</ul>pcjdevOAuth 2.0 is an open standard for authorization, published as RFC 6749 and RFC 6750 in October 2012.How to Create a Free, Fast and Secure Website with Jekyll and GitHub Pages2019-06-29T00:00:00+00:002019-06-29T00:00:00+00:00https://pcjdev.github.io/web-design/2019/06/29/how-to-create-a-free-fast-and-secure-website<p>A <a href="https://en.wikipedia.org/wiki/Static_web_page">static website</a> has noteworthy <a href="https://dzone.com/articles/6-reasons-why-you-should-go-for-a-static-website">advantages</a> over a dynamic one, like improved performance and security.</p>
<p>Here is a simple (and <a href="/notes/2019/06/27/about-this-blog-disclaimer.html">opinionated</a>) way to build a static website, with <a href="https://jekyllrb.com/">Jekyll</a> and <a href="https://pages.github.com/">GitHub Pages</a>.</p>
<h1 id="step-1-create-the-repository">Step 1: Create the repository</h1>
<p>Create a new repository named <code class="language-plaintext highlighter-rouge">username.github.io</code>, where username is your GitHub username, and clone it:</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://github.com/username/username.github.io.git
</code></pre></div></div>
<h1 id="step-2-create-the-bare-minimum-website-structure">Step 2: Create the bare minimum website structure</h1>
<p>You can create a Jekyll GitHub Pages website with just a simple text editor, without being necessary to install any additional software on your computer (<a href="https://www.ruby-lang.org/en/downloads/">Ruby</a>, <a href="https://jekyllrb.com/">Jekyll</a>, <a href="https://bundler.io/">Bundler</a>).</p>
<p>Here is an example using the default Jekyll theme, <a href="https://github.com/jekyll/minima">minima</a>, which is also one for the <a href="https://pages.github.com/themes/">supported GitHub themes</a>. Note that the pages in this example are created in <a href="https://en.wikipedia.org/wiki/Markdown">Markdown</a>, with <a href="https://jekyllrb.com/docs/front-matter/">front matter</a>.</p>
<p>Create the files:</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd </span>username.github.io
<span class="nb">touch </span>_config.yml index.md about.md
</code></pre></div></div>
<p>with the following content:</p>
<p><strong>_config.yml</strong> - the Jekyll configuration file, in YAML format</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>theme: minima
title: Simple GitHub Pages website with Jekyll
author: your_name
description: >
This is a simple GitHub Pages website with Jekyll
show_excerpts: false
minima:
date_format: "%Y-%m-%d"
twitter_username: your_username
github_username: your_username
rss: rss
plugins:
- jekyll-feed
- jekyll-seo-tag
</code></pre></div></div>
<p><strong>index.md</strong> - the homepage of your website</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>---
layout: home
---
</code></pre></div></div>
<p><strong>about.md</strong> - the about page</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>---
layout: page
title: About
permalink: /about/
---
A simple GitHub Pages website with Jekyll.
</code></pre></div></div>
<h1 id="step-3-push-the-files-to-github">Step 3: Push the files to GitHub</h1>
<p>Although is recommended to test on your local computer before pushing the changes to GitHub, if you’re impatient (and followed the above steps), you can now push the newly created files and see your blog live at https://username.github.io</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git add _config.yml index.md about.md
git commit
git push
</code></pre></div></div>
<h1 id="step-4-add-the-first-blog-post">Step 4: Add the first blog post</h1>
<p>Create the first blog post:</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">mkdir </span>_posts
<span class="nb">cd </span>_posts
<span class="nb">touch </span>2019-06-30-first-blog-post.md
</code></pre></div></div>
<p>with some content, like <a href="https://www.lipsum.com/">the standard Lorem Ipsum passage, used since the 1500s</a>:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>---
layout: post
title: "First Blog Post"
categories: web
---
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum.
</code></pre></div></div>
<h1 id="step-5-add-more-files">Step 5: Add more files</h1>
<p>Here are some recommended files for any git repository:</p>
<p><a href="https://help.github.com/en/articles/ignoring-files">.gitignore</a> - customize it for your needs</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># local bundle/gems install
.bundle
# gemfile - used for local testing
Gemfile
Gemfile.lock
# generated site
_site
# on macOS
.DS_Store
</code></pre></div></div>
<p><a href="https://editorconfig.org/">.editorconfig</a></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
</code></pre></div></div>
<p><strong>README.md</strong> - file that usually holds the description of the git repository content</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># Simple GitHub Pages site with Jekyll
A simple GitHub Pages site with Jekyll.
</code></pre></div></div>
<h1 id="step-6-customization">Step 6: Customization</h1>
<p>The following <a href="https://help.github.com/en/articles/configuring-jekyll">defaults</a> are set by GitHub, which <strong>you are free to override</strong> in your _config.yml file:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>github: [metadata]
encoding: UTF-8
kramdown:
input: GFM
hard_wrap: false
future: true
jailed: false
theme: jekyll-theme-primer
gfm_quirks: paragraph_end
</code></pre></div></div>
<p>GitHub Pages & Jekyll override the following settings in your _config.yml file, which <strong>you cannot change</strong>:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>lsi: false
safe: true
source: [your repo's top level directory]
incremental: false
highlighter: rouge
gist:
noscript: false
kramdown:
math_engine: mathjax
syntax_highlighter: rouge
</code></pre></div></div>
<p><a href="https://help.github.com/en/articles/configuring-jekyll-plugins">Default plugins</a> are <strong>enabled by default</strong> and <strong>cannot be disabled</strong>:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>- jekyll-coffeescript
- jekyll-gist
- jekyll-github-metadata
- jekyll-paginate
- jekyll-relative-links
- jekyll-optional-front-matter
- jekyll-readme-index
- jekyll-default-layout
- jekyll-titles-from-headings
</code></pre></div></div>
<p>With gem-based themes, some of the site’s directories (such as the assets, _layouts, _includes, and _sass directories) are stored in the theme’s gem, hidden from your immediate view. Yet all of the necessary directories will be read and processed during Jekyll’s build process.</p>
<p>You can <a href="https://jekyllrb.com/docs/themes/#overriding-theme-defaults">customize</a> the default theme, <a href="https://github.com/jekyll/minima">minima</a>, but pay attention to the theme <a href="https://github.com/jekyll/minima/releases">version</a>:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>open $(bundle show minima)
</code></pre></div></div>
<h1 id="step-7-test-the-website-locally">Step 7: Test the website locally</h1>
<p>You can set up a local version of your Jekyll GitHub Pages website by creating a Gemgile with the github-pages gem and test your website locally.</p>
<p>The Gemfile and Gemfile.lock files are used by Bundler to keep track of the required gems and gem versions you need to build your Jekyll website.</p>
<p>Install Jekyll and Bundler:</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>gem <span class="nb">install</span> <span class="nt">--user-install</span> bundler jekyll
</code></pre></div></div>
<p>Then, create the Gemfile:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>touch Gemfile
echo "source 'https://rubygems.org'" >> Gemfile
echo "gem 'github-pages', group: :jekyll_plugins" >> Gemfile
bundle install --path .bundle
bundle exec jekyll serve
</code></pre></div></div>
<p>Now you can browse your website locally at http://127.0.0.1:4000</p>
<p>By the way, from time to time, make sure you have the updated version of the gems:</p>
<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bundle update
</code></pre></div></div>
<p>That’s all folks!</p>
<h1 id="reference">Reference</h1>
<ul>
<li><a href="https://help.github.com/en/categories/github-pages-basics">GitHub Pages Basics</a></li>
<li><a href="https://help.github.com/en/articles/further-reading-on-github-pages">Further reading on GitHub Pages</a></li>
<li><a href="https://help.github.com/en/categories/writing-on-github">Writing on GitHub</a></li>
<li><a href="https://help.github.com/en/articles/configuring-jekyll">GitHub Pages - Configuring Jekyll</a></li>
<li><a href="https://help.github.com/en/articles/configuring-jekyll-plugins">GitHub Pages - Configuring Jekyll plugins</a></li>
<li><a href="https://jekyllrb.com/docs/github-pages/">Jekyll - GitHub Pages</a></li>
<li><a href="https://jekyllrb.com/docs/themes/">Jekyll - Themes</a></li>
<li><a href="https://jekyllrb.com/docs/posts/">Jekyll - Posts</a></li>
</ul>pcjdevA static website has noteworthy advantages over a dynamic one, like improved performance and security.About this Blog / Disclaimer2019-06-27T00:00:00+00:002019-06-27T00:00:00+00:00https://pcjdev.github.io/notes/2019/06/27/about-this-blog-disclaimer<h1 id="about-this-blog">About this Blog</h1>
<p><strong>Programming is easy</strong>. You have some requirements, and you, the programmer are put in the position to translate those requirements into another language that the computer understands and executes. Well, this is <a href="https://www.merriam-webster.com/thesaurus/opinion">my opinion</a> - as everything else on here:</p>
<blockquote>
<p>an idea that is believed to be true or valid without positive knowledge</p>
</blockquote>
<p><strong>Writing is not so easy</strong>. Because the target audience is fuzzy, not like the language that the computer understands. It’s you, the unique person, who stumbled over my blog, but also the future me.</p>
<p><strong>The promise</strong> I make to the <em>world</em>, and <em>me</em>, is that I’ll do my best to present randomly complex ideas as clearly as possible, in fields such as programming, security and life.</p>
<h1 id="discalaimer">Discalaimer</h1>
<p>Any views or opinions represented in this blog are personal.</p>
<p>All content provided on this blog is for informational purposes only and the accuracy and the completeness is not guaranteed.</p>pcjdevAbout this Blog