Skip to content

Instantly share code, notes, and snippets.

@nov
Created Sep 17, 2010
Embed
What would you like to do?
# 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