Sha256: 5d3a8ac7e26512eaca77e0cab294997be1bc0bc0d28affa8c8b483c49169d820
Contents?: true
Size: 1.87 KB
Versions: 3
Compression:
Stored size: 1.87 KB
Contents
module Rack module OAuth2 class Practice < ::Sinatra::Base register Rack::OAuth2::Sinatra oauth.scopes = "nobody sudo oauth-admin" 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
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rack-oauth2-server-1.4.6 | lib/rack/oauth2/practice.rb |
rack-oauth2-server-1.4.5 | lib/rack/oauth2/practice.rb |
rack-oauth2-server-1.4.4 | lib/rack/oauth2/practice.rb |