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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//! What a deployment can reach, and the ports that get it there.
//!
//! Two ways to become a registered client: RFC 7591 dynamic registration,
//! where the client POSTs its metadata and the server issues a credential,
//! and the Client ID Metadata Document, where the client publishes a
//! document and asserts nothing. They differ in what they send and in what
//! they establish, so they are two ports rather than one with a mode flag.
//!
//! [`Available`] is the separate question of whether either is wired up at
//! all. It is an argument to [`plan_registration`](super::plan_registration)
//! rather than something the handler reads off the identity, because the two
//! fail independently — a client can publish a document to a URL that
//! resolves nowhere, and a deployment can wire a dynamic registrar while its
//! client has no metadata to present.
use ;
use crate;
/// Registers a client dynamically through RFC 7591 §3.1.
///
/// A port of its own rather than a method on a wider trait, because a
/// deployment may be able to do only one of the two mechanisms: a client that
/// publishes a document and points at a server that implements only documents
/// has no use for this, and an adapter that claimed it would be promising a
/// capability it does not have.
///
/// Native `async fn`, so it is not object safe. That is the right trade:
/// registration happens once per client rather than per request, and the call
/// site takes `&impl DynamicRegistrar` for a zero-cost monomorphised call.
///
/// # Examples
///
/// ```
/// use protocol_droid::application::oauth::registration::{
/// ClientMetadata, DynamicRegistrar, RegistrarError,
/// };
/// use protocol_droid::domain::oauth::registration::{ClientId, RegisteredClient};
///
/// struct AlwaysTheSame;
///
/// impl DynamicRegistrar for AlwaysTheSame {
/// async fn register_dynamic(
/// &self,
/// issuer: &str,
/// _metadata: &ClientMetadata,
/// ) -> Result<RegisteredClient, RegistrarError> {
/// Ok(RegisteredClient::dynamic(
/// issuer,
/// ClientId::opaque("client-1"),
/// None,
/// )?)
/// }
/// }
/// # Ok::<(), RegistrarError>(())
/// ```
/// Fetches the Client ID Metadata Document a client published.
///
/// The counterpart to [`DynamicRegistrar`], and separate for the same reason.
/// The two differ in what they establish as well as in what they send: this one
/// yields no secret at all.
///
/// # Examples
///
/// ```
/// use protocol_droid::application::oauth::registration::{
/// MetadataDocumentLoader, RegistrarError,
/// };
/// use protocol_droid::domain::oauth::registration::{ClientId, RegisteredClient};
///
/// struct RefusesEverything;
///
/// impl MetadataDocumentLoader for RefusesEverything {
/// async fn fetch_metadata_document(
/// &self,
/// _issuer: &str,
/// _client_id: &ClientId,
/// ) -> Result<RegisteredClient, RegistrarError> {
/// Err(RegistrarError::Refused { status: 404 })
/// }
/// }
/// # Ok::<(), RegistrarError>(())
/// ```
/// What this deployment can actually reach.
///
/// A separate argument to [`plan_registration`](super::plan_registration) rather than something it reads
/// off the identity, because the two fail independently: a client can publish
/// a document to a URL that resolves nowhere, and a deployment can wire a
/// dynamic registrar while its client has no metadata to present. Planning on
/// one and discovering the other during execution is how a client ends up
/// explaining a failure it could have refused to start.