Created
September 17, 2010 17:11
-
-
Save nov/584565 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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