struct Crabbit::OAuth2Config

Overview

OAuth 2 client-credentials and refresh settings.

The token endpoint must use HTTPS unless allow_insecure_transport is explicitly enabled for isolated development. Stream endpoints must also use TLS when this configuration is attached to Configuration.

Defined in:

crabbit/oauth2.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(token_endpoint : String | URI, client_id : String, client_secret : String, grant_type : String = "client_credentials", parameters : Hash(String, String) = {} of String => String, tls_context : OpenSSL::SSL::Context::Client | Nil = nil, connection_timeout : Time::Span = 30.seconds, request_timeout : Time::Span = 60.seconds, refresh_ratio : Float64 = 0.8, refresh_retry_delay : Time::Span = 1.second, refresh_retry_max_delay : Time::Span = 30.seconds, allow_insecure_transport : Bool = false) #

Creates OAuth 2 settings.

parameters can carry provider-specific fields such as audience or scope; Crabbit always adds grant_type. The HTTP provider uses Basic client authentication and requires JSON containing access_token and a positive expires_in.

Token refresh is scheduled after refresh_ratio of the advertised lifetime. Retrieval and live re-authentication failures use exponential backoff between refresh_retry_delay and refresh_retry_max_delay.


[View source]

Instance Method Detail

def allow_insecure_transport : Bool #

Returns whether unencrypted token and Stream transports are permitted.


[View source]
def client_id : String #

Returns the OAuth 2 client identifier.


[View source]
def client_secret : String #

Returns the OAuth 2 client secret.


[View source]
def connection_timeout : Time::Span #

Returns the token-endpoint connection timeout.


[View source]
def grant_type : String #

Returns the requested grant type.


[View source]
def parameters : Hash(String, String) #

Returns additional form parameters included in token requests.


[View source]
def refresh_ratio : Float64 #

Returns the fraction of token lifetime after which proactive refresh starts.


[View source]
def refresh_retry_delay : Time::Span #

Returns the first retry delay after refresh or re-authentication failure.


[View source]
def refresh_retry_max_delay : Time::Span #

Returns the maximum retry delay.


[View source]
def request_timeout : Time::Span #

Returns the token-endpoint read and write timeout.


[View source]
def tls_context : OpenSSL::SSL::Context::Client | Nil #

Returns the optional trust/client-certificate context for the token endpoint.


[View source]
def token_endpoint : URI #

Returns the parsed token endpoint URI.


[View source]