Sha256: 61cc6e506356219d9431708d2e5b3bbab052d4723799d01e0374955a8866fda1

Contents?: true

Size: 1.94 KB

Versions: 3

Compression:

Stored size: 1.94 KB

Contents

require "rack/oauth2/server/admin"

module Rack
  module OAuth2
    class Server
      
      class Practice < ::Sinatra::Base
        register Rack::OAuth2::Sinatra

        get "/" do
          <<-HTML
<h1>Welcome to OAuth 2.0 Practice Server</h1>
<p>This practice server is for testing your OAuth 2.0 client library.</p>
<dl>
  <dt>Authorization end-point:</dt>
  <dd>http://#{request.host}:#{request.port}/oauth/authorize</dd>
  <dt>Access token end-point:<//dt>
  <dd>http://#{request.host}:#{request.port}/oauth/access_token</dd>
  <dt>Resource requiring authentication:</dt>
  <dd>http://#{request.host}:#{request.port}/secret</dd>
  <dt>Resource requiring authorization and scope "sudo":</dt>
  <dd>http://#{request.host}:#{request.port}/make</dd>
</dl>
<p>The scopes are "nobody", "sudo" and "oauth-admin".</p>
<p>You can manage client applications and tokens from the <a href="/oauth/admin">OAuth console</a>.</p>
          HTML
        end

        # -- Simple authorization --

        get "/oauth/authorize" do
          <<-HTML
<h1><a href="#{oauth.client.link}">#{oauth.client.display_name}</a> wants to access your account with the scope #{oauth.scope.join(", ")}</h1>
<form action="/oauth/grant" method="post" style="display:inline-block">
  <button>Grant</button>
  <input type="hidden" name="authorization" value="#{oauth.authorization}">
</form>
<form action="/oauth/deny" method="post" style="display:inline-block">
  <button>Deny</button>
  <input type="hidden" name="authorization" value="#{oauth.authorization}">
</form>
          HTML
        end
        post "/oauth/grant" do
          oauth.grant! "Superman"
        end
        post "/oauth/deny" do
          oauth.deny!
        end

        # -- Protected resources --

        oauth_required "/secret"
        get "/private" do
          "You're awesome!"
        end

        oauth_required "/make", :scope=>"sudo"
        get "/write" do
          "Sandwhich"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-oauth2-server-2.0.0.beta3 lib/rack/oauth2/server/practice.rb
rack-oauth2-server-2.0.0.beta2 lib/rack/oauth2/server/practice.rb
rack-oauth2-server-2.0.0.beta lib/rack/oauth2/server/practice.rb