1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use crate::{Bearer, Claims, IdToken, StandardClaims};
pub use biscuit::jws::Compact as Jws;
use biscuit::CompactJson;

/// An OpenID Connect token. This is the only token allowed by spec.
/// Has an access_token for bearer, and the id_token for authentication.
/// Wraps an oauth bearer token.
pub struct Token<C: CompactJson + Claims = StandardClaims> {
    pub bearer: Bearer,
    pub id_token: Option<IdToken<C>>,
}

impl<C: CompactJson + Claims> From<Bearer> for Token<C> {
    fn from(bearer: Bearer) -> Self {
        let id_token = bearer
            .id_token
            .as_ref()
            .map(|token| Jws::new_encoded(token));
        Self { bearer, id_token }
    }
}