module OAuth
Overview
The OAuth module provides anOAuth::Consumer as specified by
RFC 5849.
NOTE To useOAuth, you must explicitly import it withrequire "oauth"
Performing HTTP client requests with OAuth authentication
Assuming you have an access token, its secret, the consumer key and the consumer secret,
you can setup anHTTP::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 withHTTP::Client#before_request to add an authorization
header to every request.
Alternatively, you can create anOAuth::Consumer and then invoke its
OAuth::Consumer#authenticate method, or create anOAuth::AccessToken
and invoke itsOAuth::AccessToken#authenticate.
Obtaining access tokens
SeeOAuth::Consumer for an example.
Defined in:
oauth/access_token.croauth/oauth.cr
Class Method Summary
-
.authenticate(client : HTTP::Client, token : String | Nil, token_secret : String | Nil, consumer_key : String, consumer_secret : String, extra_params : Hash(String, String) | Nil = nil) : Nil
Sets up an
HTTP::Clientto add an OAuth authorization header to every request performed.
Class Method Detail
Sets up anHTTP::Client to add an OAuth authorization header to every request performed.
Check this module's docs for an example usage.