1
use std::sync::Arc;
2

            
3
use oxide_auth::primitives::scope::Scope;
4
use oxide_auth_async::{
5
    code_grant::{
6
        access_token::{Endpoint as AccessTokenEndpoint, Extension as AccessTokenExtension},
7
        authorization::{Endpoint as AuthorizationEndpoint, Extension as AuthorizationExtension},
8
        refresh::Endpoint as RefreshEndpoint,
9
        resource::Endpoint as ResourceEndpoint,
10
    },
11
    primitives::{Authorizer, Issuer, Registrar},
12
};
13

            
14
use super::primitive::Primitive;
15
use crate::models::Model;
16

            
17
#[derive(Clone)]
18
pub struct Endpoint {
19
    primitive: Primitive,
20
    extension_fallback: (),
21
    scopes: Vec<Scope>,
22
}
23

            
24
impl Endpoint {
25
27918
    pub fn new(model: Arc<dyn Model>, resource_scopes: Option<&str>) -> Self {
26
27918
        Endpoint {
27
27918
            primitive: Primitive::new(model.clone()),
28
27918
            extension_fallback: (),
29
27918
            scopes: match resource_scopes {
30
634
                None => vec![],
31
27284
                Some(scopes) => vec![scopes.parse().unwrap()],
32
            },
33
        }
34
27918
    }
35
}
36

            
37
impl AccessTokenEndpoint for Endpoint {
38
262
    fn registrar(&self) -> &(dyn Registrar + Sync) {
39
262
        &self.primitive
40
262
    }
41

            
42
254
    fn authorizer(&mut self) -> &mut (dyn Authorizer + Send) {
43
254
        &mut self.primitive
44
254
    }
45

            
46
250
    fn issuer(&mut self) -> &mut (dyn Issuer + Send) {
47
250
        &mut self.primitive
48
250
    }
49

            
50
248
    fn extension(&mut self) -> &mut (dyn AccessTokenExtension + Send) {
51
248
        &mut self.extension_fallback
52
248
    }
53
}
54

            
55
impl AuthorizationEndpoint for Endpoint {
56
604
    fn registrar(&self) -> &(dyn Registrar + Sync) {
57
604
        &self.primitive
58
604
    }
59

            
60
274
    fn authorizer(&mut self) -> &mut (dyn Authorizer + Send) {
61
274
        &mut self.primitive
62
274
    }
63

            
64
298
    fn extension(&mut self) -> &mut (dyn AuthorizationExtension + Send) {
65
298
        &mut self.extension_fallback
66
298
    }
67
}
68

            
69
impl RefreshEndpoint for Endpoint {
70
26
    fn registrar(&self) -> &(dyn Registrar + Sync) {
71
26
        &self.primitive
72
26
    }
73

            
74
42
    fn issuer(&mut self) -> &mut (dyn Issuer + Send) {
75
42
        &mut self.primitive
76
42
    }
77
}
78

            
79
impl ResourceEndpoint for Endpoint {
80
498
    fn scopes(&mut self) -> &[Scope] {
81
498
        self.scopes.as_slice()
82
498
    }
83

            
84
498
    fn issuer(&mut self) -> &mut (dyn Issuer + Send) {
85
498
        &mut self.primitive
86
498
    }
87
}