Commit 8d68697
Changed files (7)
app
controllers
oauth
config
doc
lib
tasks
spec
app/controllers/oauth/tokens_controller.rb
@@ -2,6 +2,8 @@
module Oauth
class TokensController < ApplicationController
+ protect_from_forgery with: :null_session
+
def create
response.headers['Cache-Control'] = 'no-store'
response.headers['Pragma'] = 'no-cache'
config/jekyll.yml
@@ -17,7 +17,7 @@ title: Proof - API Documentation
email: mokha@example.com
description: >- # this means to ignore newlines until "baseurl:"
API documentation for Proof.
-baseurl: "doc" # the subpath of your site, e.g. /blog
+baseurl: "/doc" # the subpath of your site, e.g. /blog
url: "" # the base hostname & protocol for your site, e.g. http://example.com
github_username: mokhan
source: 'doc'
doc/_posts/2018-10-28-oauth-tokens.markdown
@@ -0,0 +1,42 @@
+---
+layout: post
+title: "OAuth 2.0 - Tokens"
+date: 2018-10-28 14:00:00 -0700
+permalink: /oauth/tokens.html
+categories: oauth
+---
+
+The Tokens endpoint adheres to [RFC-6749](https://tools.ietf.org/html/rfc6749).
+
+## Authorization Code Grant Flow
+
+```text
+ +----------+
+ | Resource |
+ | Owner |
+ | |
+ +----------+
+ ^
+ |
+ (B)
+ +----|-----+ Client Identifier +---------------+
+ | -+----(A)-- & Redirection URI ---->| |
+ | User- | | Authorization |
+ | Agent -+----(B)-- User authenticates --->| Server |
+ | | | |
+ | -+----(C)-- Authorization Code ---<| |
+ +-|----|---+ +---------------+
+ | | ^ v
+ (A) (C) | |
+ | | | |
+ ^ v | |
+ +---------+ | |
+ | |>---(D)-- Authorization Code ---------' |
+ | Client | & Redirection URI |
+ | | |
+ | |<---(E)----- Access Token -------------------'
+ +---------+ (w/ Optional Refresh Token)
+```
+[RFC-6749 Section 4.1](https://tools.ietf.org/html/rfc6749#section-4.1)
+
+{% include oauth-tokens-authorization-code.html %}
lib/tasks/doc.rake
@@ -22,7 +22,7 @@ namespace :doc do
end
desc "Watch and rebuild static pages"
- task watch: [:environment] do
+ task watch: [:clean, :environment] do
custom_options = default_options.merge(watch: true)
Jekyll::Commands::Build.process(custom_options)
end
spec/documentation.rb
@@ -28,13 +28,24 @@ RSpec.configure do |config|
end
RSpec.describe "documentation" do
- let(:client) { Net::Hippie::Client.new(verify_mode: OpenSSL::SSL::VERIFY_NONE) }
+ let(:hippie) { Net::Hippie::Client.new(verify_mode: OpenSSL::SSL::VERIFY_NONE) }
let(:host) { ENV.fetch('HOST', 'proof.test') }
let(:scheme) { ENV.fetch('SCHEME', 'https') }
specify do
VCR.use_cassette("get-well-known-oauth-authorization-server") do
- response = client.get("#{scheme}://#{host}/.well-known/oauth-authorization-server")
+ response = hippie.get("#{scheme}://#{host}/.well-known/oauth-authorization-server")
+ expect(response.code).to eql('200')
+ end
+ end
+
+ specify do
+ client = create(:client)
+ authorization = create(:authorization, client: client)
+ headers = { 'Authorization' => ActionController::HttpAuthentication::Basic.encode_credentials(client.to_param, client.password) }
+ body = { grant_type: 'authorization_code', code: authorization.code }
+ VCR.use_cassette("oauth-tokens-authorization-code") do
+ response = hippie.post("#{scheme}://#{host}/oauth/tokens", body: body, headers: headers)
expect(response.code).to eql('200')
end
end