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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! Handling Proof Key for Code Exchange.
//!
//! PKCE specification is defined in [RFC 7636](https://datatracker.ietf.org/doc/html/rfc7636).
//!
//! # Abstract
//!
//! PKCE (pronounced "pixy") is a method to secure authorization codes in OAuth 2.0
//! *authorization code* flow. It is designed to prevent interception attacks.
//!
//! # Abbreviations
//!
//! - `PKCE`: Proof Key for Code Exchange;
//! - `Auth`: Authorization.
//!
//! # Protocol
//!
//! ```text
//! +--------------+
//! | Auth |
//! +--------+ | +----------+ |
//! | |--(1)- Auth Request + code_challenge ---->| | |
//! | | + code_challenge_method | | Auth | |
//! | | | | Endpoint | |
//! | |<-(2)----------- Auth Code ---------------| | |
//! | | | +----------+ |
//! | Client | | |
//! | | | +----------+ |
//! | |--(3)- Token Request + code_verifier ---->| | |
//! | | | | Tokens | |
//! | | | | Endpoint | |
//! | |<-(4)------------- Token -----------------| | |
//! +--------+ | +----------+ |
//! | Server |
//! +--------------+
//! ```
//!
//! ## 0. Code creation
//!
//! The *client* generates the `code_verifier` and derives the `code_challenge` from it
//! using the `code_challenge_method`.
//!
//! ## 1. Auth Request
//!
//! The *client* sends the `code_challenge` and the `code_challenge_method` along with the
//! regular `authorization_code` request to the *Auth Endpoint*.
//!
//! ## 2. Auth Code
//!
//! The *server* stores the `code_challenge` and the `code_challenge_method` for later use,
//! responding with the usual authorization `code`.
//!
//! ## 3. Token Request
//!
//! The *client* sends the `code_verifier` along with the regular request to the *Tokens Endpoint*.
//!
//! ## 4. Token
//!
//! The *server* verifies the `code_verifier` against the stored `code_challenge` using the
//! `code_challenge_method`, responding with the `token` if the verification is successful.
//!
//! # Examples
//!
//! Generating `code_verifier` and deriving `code_challenge` in one go:
//!
//! ```
//! use pkce_std::Code;
//!
//! let code = Code::generate_default();
//! ```
//!
//! Alternatively, generating from random bytes:
//!
//! ```
//! use pkce_std::Code;
//!
//! let code = Code::generate_encode_default();
//! ```
//!
//! Decoupling verifier and challenge:
//!
//! ```
//! # use pkce_std::Code;
//! #
//! # let code = Code::generate_default();
//! #
//! let (verifier, challenge) = code.into_pair();
//! ```
//!
//! Verifying `code_verifier` against `code_challenge`:
//!
//! ```
//! # use pkce_std::Code;
//! #
//! # let (verifier, challenge) = Code::generate_default().into_pair();
//! #
//! let valid = verifier.verify(&challenge);
//! ```
pub use Challenge;
pub use ;
pub use Count;
pub use Length;
pub use Method;
pub use Verifier;