Authentication filter for handling OAuth negotiation. Used in WWWAuth.
CAUTION: This impl only support ‘#7 Accessing Protected Resources’ in OAuth Core 1.0 spec for now. You need to obtain Access token and Access secret by yourself.
CAUTION: This impl does NOT support OAuth Request Body Hash spec for now. oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html
Creates new DigestAuth filter.
# File lib/httpclient/auth.rb, line 802 def initialize super @config = nil # common config @auth = {} # configs for each site @challenge = {} @nonce_count = 0 @signature_handler = { 'HMAC-SHA1' => method(:sign_hmac_sha1) } @scheme = "OAuth" end
Challenge handler: remember URL for response.
challenge() in OAuth handler always returns false to avoid connection retry which should not work in OAuth authentication context. This method just remember URL (nil means ‘any’) for the next connection. Normally OAuthClient handles this correctly but see how it uses when you need to use this class directly.
# File lib/httpclient/auth.rb, line 875 def challenge(uri, param_str = nil) synchronize { if uri.nil? @challenge[nil] = true else @challenge[urify(uri)] = true end false } end
# File lib/httpclient/auth.rb, line 797 def escape(str) self.class.escape(str) end
Response handler: returns credential. It sends cred only when a given uri is;
child page of challengeable(got *Authenticate before) uri and,
child page of defined credential
# File lib/httpclient/auth.rb, line 856 def get(req) target_uri = req.header.request_uri synchronize { return nil unless @challenge[nil] or @challenge.find { |uri, ok| Util.uri_part_of(target_uri, uri) and ok } config = do_get_config(target_uri) || @config return nil unless config calc_cred(req, config) } end
Get authentication credential.
# File lib/httpclient/auth.rb, line 846 def get_config(uri = nil) synchronize { do_get_config(uri) } end
Resets challenge state. Do not send ‘*Authorization’ header until the server sends ‘*Authentication’ again.
# File lib/httpclient/auth.rb, line 816 def reset_challenge synchronize do @challenge.clear end end
Set authentication credential. You cannot set OAuth config via WWWAuth#set_auth. Use OAuth#config=
# File lib/httpclient/auth.rb, line 824 def set(*args) # not supported end
Generated with the Darkfish Rdoc Generator 2.