1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
extern crate actix;
extern crate actix_web;
extern crate futures;
extern crate serde_urlencoded;
mod future_endpoint;
mod endpoint;
pub mod message;
pub mod request;
#[cfg(test)]
mod tests;
use std::fmt;
use std::error;
use self::actix_web::{HttpRequest, HttpResponse};
use self::actix_web::ResponseError;
pub use endpoint::{PreGrant, OAuthError, OwnerConsent, OwnerSolicitor};
pub use primitives::grant::Grant;
pub use self::request::OAuthFuture;
pub use self::request::OAuthRequest;
pub use self::request::OAuthResponse;
pub use self::future_endpoint::{ResourceProtection, access_token, authorization, refresh, resource};
pub trait OAuth {
fn oauth2(self) -> OAuthFuture;
}
pub struct AsActor<P>(pub P);
#[derive(Debug)]
pub struct OAuthFailure(OAuthError);
impl<'a, State> OAuth for &'a HttpRequest<State> {
fn oauth2(self) -> OAuthFuture {
OAuthFuture::new(self)
}
}
impl fmt::Display for OAuthFailure {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
impl From<OAuthError> for OAuthFailure {
fn from(err: OAuthError) -> Self {
OAuthFailure(err)
}
}
impl error::Error for OAuthFailure { }
impl ResponseError for OAuthFailure {
fn error_response(&self) -> HttpResponse {
match self.0 {
OAuthError::DenySilently => HttpResponse::BadRequest().finish(),
OAuthError::PrimitiveError => HttpResponse::InternalServerError().finish(),
OAuthError::BadRequest => HttpResponse::BadRequest().finish(),
}
}
}