简体   繁体   中英

OAuth signature verification fails

I'm having some problem setting up an oauth provider with two-legged authentication.

I'm using the oauth-plugin gem and the oauth gem, everything works fine except for my "update" requests. The signature verification process keeps failing.

Here is what I'm doing:

In the client, I'm using

oauth = OAuth::AccessToken.new(OAuth::Consumer.new(app_key, app_secret, :site => @api_endpoint))
oauth.get("http://localhost/api/v1/users/1")
oauth.post("http://localhost/api/v1/users", {:email => "testemail@mysite.com"})
oauth.put("http://localhost/api/v1/users", {:tags => ["some", "new", "tags"]})
oauth.delete("http://localhost/api/v1/users/1")

get, post and delete all go through authentication fine, but update fails.

On the server side, I have my ClientApplication class set up

  def self.verify_request(request, options = {}, &block)
    begin
      signature = OAuth::Signature.build(request, options, &block)
      return false unless OauthNonce.remember(signature.request.nonce, signature.request.timestamp)
      value = signature.verify
      value
    rescue OAuth::Signature::UnknownSignatureMethod => e
      false
    end
  end

signature.verify fails on my update requests and passes on the other 3 requests. Anybody know what's happening?

Turns out the problem is with passing the params through the body.
I moved the params into the url with Addressable/uri, and that fixed the problem. It's gonna be a little limiting in terms of length, but ok for now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM