actix_web_httpauth/headers/www_authenticate/challenge/bearer/
builder.rs

1use std::borrow::Cow;
2
3use super::{Bearer, Error};
4
5/// Builder for the [`Bearer`] challenge.
6///
7/// It is up to implementor to fill all required fields, neither this `Builder` nor [`Bearer`]
8/// provide any validation.
9#[derive(Debug, Default)]
10pub struct BearerBuilder(Bearer);
11
12impl BearerBuilder {
13    /// Provides the `scope` attribute, as defined in [RFC 6749 §3.3].
14    ///
15    /// [RFC 6749 §3.3]: https://tools.ietf.org/html/rfc6749#section-3.3
16    pub fn scope<T>(mut self, value: T) -> Self
17    where
18        T: Into<Cow<'static, str>>,
19    {
20        self.0.scope = Some(value.into());
21        self
22    }
23
24    /// Provides the `realm` attribute, as defined in [RFC 2617].
25    ///
26    /// [RFC 2617]: https://tools.ietf.org/html/rfc2617
27    pub fn realm<T>(mut self, value: T) -> Self
28    where
29        T: Into<Cow<'static, str>>,
30    {
31        self.0.realm = Some(value.into());
32        self
33    }
34
35    /// Provides the `error` attribute, as defined in [RFC 6750, Section 3.1].
36    ///
37    /// [RFC 6750 §3.1]: https://tools.ietf.org/html/rfc6750#section-3.1
38    pub fn error(mut self, value: Error) -> Self {
39        self.0.error = Some(value);
40        self
41    }
42
43    /// Provides the `error_description` attribute, as defined in [RFC 6750, Section 3].
44    ///
45    /// [RFC 6750 §3]: https://tools.ietf.org/html/rfc6750#section-3
46    pub fn error_description<T>(mut self, value: T) -> Self
47    where
48        T: Into<Cow<'static, str>>,
49    {
50        self.0.error_description = Some(value.into());
51        self
52    }
53
54    /// Provides the `error_uri` attribute, as defined in [RFC 6750 §3].
55    ///
56    /// It is up to implementor to provide properly-formed absolute URI.
57    ///
58    /// [RFC 6750 §3](https://tools.ietf.org/html/rfc6750#section-3)
59    pub fn error_uri<T>(mut self, value: T) -> Self
60    where
61        T: Into<Cow<'static, str>>,
62    {
63        self.0.error_uri = Some(value.into());
64        self
65    }
66
67    /// Consumes the builder and returns built `Bearer` instance.
68    pub fn finish(self) -> Bearer {
69        self.0
70    }
71}