NOTE To use
OAuth, you must explicitly import it with
Assuming you have an access token, its secret, the consumer key and the consumer secret,
you can setup an
HTTP::Client to be authenticated with OAuth using this code:
require "http/client" require "oauth" token = "some_token" secret = "some_secret" consumer_key = "some_consumer_key" consumer_secret = "some_consumer_secret" # Create an HTTP::Client as usual client = HTTP::Client.new("api.example.com", tls: true) # Prepare it for using OAuth authentication OAuth.authenticate(client, token, secret, consumer_key, consumer_secret) # Execute requests as usual: they will be authenticated client.get("/some_path")
This is implemented with
HTTP::Client#before_request to add an authorization
header to every request.
OAuth::Consumer for an example.
.authenticate(client : HTTP::Client, token, token_secret, consumer_key, consumer_secret, extra_params = nil) : Nil
Sets up an
HTTP::Clientto add an OAuth authorization header to every request performed.