I figured out how to do this if my ActiveResource classes inherit from an intermediate class:
class Resource < ActiveResource::Base end class MyClass < Resource end
This allows you to dynamically set authentication (as well as the site, format, etc.) for all classes that inherit from the intermediate resource class:
if the user has configured OAuth2:
Resource.headers['authorization'] = 'Bearer ' + my_oauth2_token
or if the user just uses basic authentication:
Resource.user = my_user_name Resource.password = my_password
Hope this helps someone!
source share