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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
//! Provides actix message encapsulations. //! //! The http types, especially `HttpRequest` can not be shared across threads. Therefore, //! the relevant information is extracted into special message types first using the `OAuth` trait //! found in the module above. mod authorizer; mod issuer; mod registrar; use super::actix::prelude::Message; use super::ResourceProtection; use super::request::{OAuthRequest as ResolvedRequest}; use primitives::grant::Grant; use endpoint::WebRequest; pub use self::authorizer::{Authorize, Extract}; pub use self::issuer::{Issue, RecoverToken, RecoverRefresh, Refresh}; pub use self::registrar::{BoundRedirect, Check, Negotiate}; /// A request for an authorization code from an endpoint actor. /// /// ## Example /// /// Here is a way to request an authorization code response from some actix recipient. /// /// ```no_run /// # extern crate actix; /// # extern crate actix_web; /// # extern crate futures; /// # extern crate oxide_auth; /// use oxide_auth::frontends::actix::{OAuth, OAuthError, OAuthResponse}; /// use oxide_auth::frontends::actix::message::AuthorizationCode; /// # use oxide_auth::frontends::actix::request::OAuthRequest; /// # use actix::Recipient; /// # use actix_web::HttpRequest; /// # use futures::Future; /// # fn main() { /// /// fn handle(request: HttpRequest, recipient: Recipient<AuthorizationCode>) /// -> impl Future<Item=OAuthResponse, Error=OAuthError> /// { /// request.oauth2() /// .and_then(move |request| recipient /// .send(request.authorization_code()) /// // Merge `MailboxError` and response ´OAuthError` /// .map_err(|_| OAuthError::DenySilently) /// .and_then(|x| x)) /// } /// # } /// ``` pub struct AuthorizationCode<W: WebRequest=ResolvedRequest>(pub W); /// A request for a bearer token. /// /// ## Example /// /// Here is a way to request an access token response from some actix recipient. /// /// ```no_run /// # extern crate actix; /// # extern crate actix_web; /// # extern crate futures; /// # extern crate oxide_auth; /// use oxide_auth::frontends::actix::{OAuth, OAuthError, OAuthResponse}; /// use oxide_auth::frontends::actix::message::AccessToken; /// # use oxide_auth::frontends::actix::request::OAuthRequest; /// # use actix::Recipient; /// # use actix_web::HttpRequest; /// # use futures::Future; /// # fn main() { /// /// fn handle(request: HttpRequest, recipient: Recipient<AccessToken>) /// -> impl Future<Item=OAuthResponse, Error=OAuthError> /// { /// request.oauth2() /// .and_then(move |request| recipient /// .send(request.access_token()) /// // Merge `MailboxError` and response ´OAuthError` /// .map_err(|_| OAuthError::DenySilently) /// .and_then(|x| x)) /// } /// # } /// ``` pub struct AccessToken<W: WebRequest=ResolvedRequest>(pub W); /// A request for a resource, utilizing a bearer token. /// /// ## Example /// /// Here is a way to test an authorizing request against an actix recipient. /// /// ```no_run /// # extern crate actix; /// # extern crate actix_web; /// # extern crate futures; /// # extern crate oxide_auth; /// use oxide_auth::frontends::actix::{Grant, OAuth, OAuthError, OAuthResponse, ResourceProtection}; /// use oxide_auth::frontends::actix::message::Resource; /// # use oxide_auth::frontends::actix::request::OAuthRequest; /// # use actix::Recipient; /// # use actix_web::HttpRequest; /// # use futures::Future; /// # fn main() { /// /// fn handle(request: HttpRequest, recipient: Recipient<Resource>) /// -> impl Future<Item=Grant, Error=ResourceProtection<OAuthResponse>> /// { /// request.oauth2() /// .map_err(ResourceProtection::Error) /// .and_then(move |request| recipient /// .send(request.resource()) /// // Merge `MailboxError` and response ´OAuthError` /// .map_err(|_| ResourceProtection::Error(OAuthError::DenySilently)) /// .and_then(|x| x)) /// } /// # } /// ``` pub struct Resource<W: WebRequest=ResolvedRequest>(pub W); impl<W: WebRequest> Message for AuthorizationCode<W> where W: Send + Sync + 'static, W::Response: Send + Sync + 'static { type Result = Result<W::Response, W::Error>; } impl<W: WebRequest> Message for AccessToken<W> where W: Send + Sync + 'static, W::Response: Send + Sync + 'static { type Result = Result<W::Response, W::Error>; } impl<W: WebRequest> Message for Resource<W> where W: Send + Sync + 'static { type Result = Result<Grant, ResourceProtection<W::Response>>; }