1use crate::server::Authorization;
2use serde::{Deserialize, Serialize};
3use std::collections::BTreeSet;
4use swagger::{
5 auth::{Basic, Bearer},
6 ApiError,
7};
8
9#[derive(Debug, Serialize, Deserialize)]
10pub struct Claims {
11 pub sub: String,
12 pub iss: String,
13 pub aud: String,
14 pub company: String,
15 pub exp: u64,
16 pub scopes: String,
17}
18
19pub trait AuthenticationApi {
20 fn bearer_authorization(&self, token: &Bearer) -> Result<Authorization, ApiError>;
22
23 fn apikey_authorization(&self, token: &str) -> Result<Authorization, ApiError>;
25
26 fn basic_authorization(&self, basic: &Basic) -> Result<Authorization, ApiError>;
28}
29
30use swagger::auth::{AllowAllAuthenticator, RcBound, Scopes};
32
33fn dummy_authorization() -> Authorization {
34 Authorization {
38 subject: "Dummy".to_owned(),
39 scopes: Scopes::Some(BTreeSet::new()), issuer: None,
41 }
42}
43
44impl<T, RC> AuthenticationApi for AllowAllAuthenticator<T, RC>
45where
46 RC: RcBound,
47 RC::Result: Send + 'static,
48{
49 fn bearer_authorization(&self, _token: &Bearer) -> Result<Authorization, ApiError> {
51 Ok(dummy_authorization())
52 }
53
54 fn apikey_authorization(&self, _apikey: &str) -> Result<Authorization, ApiError> {
56 Ok(dummy_authorization())
57 }
58
59 fn basic_authorization(&self, _basic: &Basic) -> Result<Authorization, ApiError> {
61 Ok(dummy_authorization())
62 }
63}