Class: CloudKit::OAuthFilter
- Includes:
- Util
- Defined in:
- lib/cloudkit/oauth_filter.rb
Overview
An OAuthFilter provides both OAuth 1.0 support, plus OAuth Discovery.
Responds to the following URIs as part of the OAuth 1.0 “dance”:
/oauth/request_tokens
/oauth/authorization
/oauth/authorized_request_tokens/{id}
/oauth/access_tokens
Responds to the following URIs as part of OAuth Discovery:
/oauth
/oauth/meta
See also:
-
Thread covering /oauth and /oauth/meta URIs.
Constant Summary collapse
- @@lock =
Mutex.new
- @@store =
nil
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ OAuthFilter
constructor
A new instance of OAuthFilter.
- #store ⇒ Object
Methods included from Util
Constructor Details
#initialize(app, options = {}) ⇒ OAuthFilter
Returns a new instance of OAuthFilter.
27 28 29 30 |
# File 'lib/cloudkit/oauth_filter.rb', line 27 def initialize(app, ={}) @app = app @options = end |
Instance Method Details
#call(env) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cloudkit/oauth_filter.rb', line 32 def call(env) @@lock.synchronize do @@store = OAuthStore.new end unless @@store request = Request.new(env) request.announce_auth(CLOUDKIT_OAUTH_FILTER_KEY) return xrds_location(request) if oauth_disco_draft2_xrds?(request) return @app.call(env) if request.path_info == '/' load_user_from_session(request) begin case request when r(:get, '/oauth/meta') (request) when r(:post, '/oauth/request_tokens', ['oauth_consumer_key']) create_request_token(request) when r(:get, '/oauth/authorization', ['oauth_token']) (request) when r(:put, '/oauth/authorized_request_tokens/:id', ['submit' => 'Approve']) # Temporarily relying on a button value until pluggable templates are # introduced in 1.0. (request) when r(:put, '/oauth/authorized_request_tokens/:id', ['submit' => 'Deny']) # See previous comment. deny_request_token(request) when r(:post, '/oauth/authorized_request_tokens/:id', [{'_method' => 'PUT'}]) (request) when r(:post, '/oauth/access_tokens') create_access_token(request) when r(:get, '/oauth') get_descriptor(request) else inject_user_or_challenge(request) @app.call(env) end rescue OAuth::Signature::UnknownSignatureMethod # The OAuth spec suggests a 400 status, but serving a 401 with the # meta/challenge info seems more appropriate as the OAuth metadata # specifies the supported signature methods, giving the user agent an # opportunity to fix the error. return challenge(request, 'unknown signature method') end end |
#store ⇒ Object
78 |
# File 'lib/cloudkit/oauth_filter.rb', line 78 def store; @@store; end |