require "rack/oauth2/server/admin" module Rack module OAuth2 class Server class Practice < ::Sinatra::Base register Rack::OAuth2::Sinatra get "/" do <<-HTML OAuth 2.0 Practice Server

Welcome to OAuth 2.0 Practice Server

This practice server is for testing your OAuth 2.0 client library.

Authorization end-point:
http://#{request.host}:#{request.port}/oauth/authorize
Access token end-point:
http://#{request.host}:#{request.port}/oauth/access_token
Resource requiring authentication:
http://#{request.host}:#{request.port}/secret
Resource requiring authorization and scope "sudo":
http://#{request.host}:#{request.port}/make

The scope can be "nobody", "sudo", "oauth-admin" or combination of the three.

You can manage client applications and tokens from the OAuth console.

HTML end # -- Simple authorization -- get "/oauth/authorize" do <<-HTML OAuth 2.0 Practice Server

#{oauth.client.display_name} wants to access your account with the scope #{oauth.scope.join(", ")}

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