module OAuth2

Overview

The OAuth module provides anOAuth2::Client as specified byRFC 6749.

NOTE To useOAuth2, you must explicitly import itwithrequire "oauth2"

Performing HTTP client requestswith OAuth2 authentication

Assuming you have an access token, you can setup anHTTP::Client to be authenticatedwith OAuth2 using this code:

require "http/client"
require "oauth2"

# Here we use a bearer token, but it could be a mac token. We also set the
# expires in value to 172,800 seconds, or 48 hours
access_token = OAuth2::AccessToken::Bearer.new("some_access_token", 172_800)

# Create an HTTP::Client
client = HTTP::Client.new("api.example.com", tls: true)

# Prepare it for using OAuth2 authentication
access_token.authenticate(client)

# Execute requests as usual: they will be authenticated
client.get("/some_path")

This is implementedwithHTTP::Client#before_request to add an authorization header to every request.

Obtaining access tokens

SeeOAuth2::Client for an example.

Defined in:

oauth2/auth_scheme.cr
oauth2/oauth2.cr