1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! Small building blocks for Twitch integrations.
//!
//! `barbed` currently includes:
//!
//! - OAuth authorize URL construction and signed state verification
//! - Helix request builders and response parsers
//! - EventSub WebSocket payload decoding and chat subscription helpers
//! - HMAC signing helpers for short-lived tokens and state payloads
//!
//! The default crate stays runtime-agnostic. Enable the `cloudflare-worker`
//! feature to send [`http::PreparedRequest`] values via the Cloudflare
//! Workers `Fetch` API. Enable the `reqwest-client` and `tokio-eventsub`
//! features for a native Rust runtime.
//!
//! # Feature Flags
//!
//! - `cloudflare-worker`: adds transport helpers built on the Cloudflare
//! Workers `Fetch` API.
//! - `reqwest-client`: adds native HTTP helpers built on `reqwest`.
//! - `tokio-eventsub`: adds the native EventSub websocket client/runtime.
//!
//! # MSRV
//!
//! `barbed` currently targets Rust `1.85.0`.
//!
//! # Example
//!
//! ```rust
//! use barbed::http::percent_decode;
//! use barbed::oauth::{OAuthStatePayload, build_authorize_url, verify_oauth_state};
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
//! struct AuthState {
//! redirect_to: String,
//! expires_at_ms: i64,
//! }
//!
//! impl OAuthStatePayload for AuthState {
//! fn expires_at_ms(&self) -> i64 {
//! self.expires_at_ms
//! }
//! }
//!
//! let state = AuthState {
//! redirect_to: "/dashboard".to_string(),
//! expires_at_ms: 1_700_000_060_000,
//! };
//!
//! let authorize_url = build_authorize_url(
//! "client-id",
//! "https://example.com/twitch/callback",
//! &["user:read:chat"],
//! &state,
//! "super-secret",
//! )?;
//!
//! let encoded_state = authorize_url
//! .split("&state=")
//! .nth(1)
//! .expect("missing state parameter");
//! let signed_state = percent_decode(encoded_state)?;
//! let verified: AuthState =
//! verify_oauth_state("super-secret", &signed_state, 1_700_000_000_000)?;
//!
//! assert_eq!(verified, state);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! This crate is intentionally small and still settling; expect API breakage
//! across `0.0.x` releases.
/// Cloudflare Workers transport helpers for prepared Twitch API requests.
/// EventSub payload types and websocket subscription helpers.
/// Helix request builders and response parsers.
/// Percent-encoding and form-body helpers used by the request builders.
/// Identity types for authenticated Twitch users.
/// Native async helpers for OAuth, Helix, and EventSub interactions.
/// OAuth URL construction, token lifecycle helpers, and signed state handling.
/// Shared HMAC signing helpers for short-lived payloads.
/// Backwards-compatible alias for the legacy `client` module path.
/// Re-export of the core Twitch identity model.
pub use TwitchIdentity;