Skip to content

Instantly share code, notes, and snippets.

@nov
Created September 17, 2010 17:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nov/584565 to your computer and use it in GitHub Desktop.
Save nov/584565 to your computer and use it in GitHub Desktop.
# environment.rb
#
# These are models you should define. (you can change the model name, of course)
# * Oauth2::AccessToken
Rails::Initializer.run do |config|
:
require 'rack/oauth2'
oauth2_authenticator = lambda do |request|
access_token = Oauth2::AccessToken.find_by_token(request.access_token)
if access_token.blank?
request.invalid_token! "Given access token is invalid."
elsif access_token.expired?
request.expired_token! "Given access token has been expired."
elsif access_token.revoked?
request.invalid_token! "Given access token has been revoked."
end
end
config.middleware.insert_before(RestfulJsonpMiddleware, Rack::OAuth2::Server::Resource, "server.example.com", &oauth2_authenticator)
:
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment