HTTParty: Changing authentication types per instance (ie toggling basic and digest auths) causes an Argument Error

时间:2018-02-01 18:19:54

标签: ruby-on-rails api-design httparty

Depending on a particular device type, we will toggle between basic auth (default) to digest auth.

When implementing this decision, getting this error:

ArgumentError: only one authentication method, :basic_auth or :digest_auth may be used at a time

If forced to basic only - works fine. Including HTTParty in both client classes. And including it in the parent class for a particular request that is device specific.

Any insight would be appreciated.

2 个答案:

答案 0 :(得分:0)

I think the crux of this is that HTTParty is not thread-safe and thus those instances are shared across classes and thus why you cannot change lower-level configuration changes.

Honestly I ditched HTTParty because of this and moved to RestClient which is more full-featured.

答案 1 :(得分:0)

所以......在深入挖掘他们的gem之后,看起来他们在初始化Request类时就开始构建一个基本的auth - 即使选项中存在digest auth hash。

没有考虑检查选项,只需解析凭据的URL并立即在请求的选项中构建基本身份验证。这可以解决上面的错误。

在我的本地项目中为初始化方法检查预先存在的auths的条件解决了我的问题。