openid/
token.rs

1pub use biscuit::jws::Compact as Jws;
2use biscuit::CompactJson;
3
4use crate::{Bearer, Claims, IdToken, StandardClaims};
5
6/// An OpenID Connect token. This is the only token allowed by spec.
7/// Has an `access_token` for bearer, and the `id_token` for authentication.
8/// Wraps an oauth bearer token.
9#[allow(missing_debug_implementations)]
10pub struct Token<C: CompactJson + Claims = StandardClaims> {
11    /// Bearer Token.
12    ///
13    /// `access_token`
14    pub bearer: Bearer,
15    /// ID Token
16    ///
17    /// `id_token`
18    pub id_token: Option<IdToken<C>>,
19}
20
21impl<C: CompactJson + Claims> From<Bearer> for Token<C> {
22    fn from(bearer: Bearer) -> Self {
23        let id_token = bearer
24            .id_token
25            .as_ref()
26            .map(|token| Jws::new_encoded(token));
27        Self { bearer, id_token }
28    }
29}