pub trait OAuthOperation: Sized + 'static {
    type Item: 'static;
    type Error: Debug + 'static;
    fn run<E>(self, endpoint: E) -> Result<Self::Item, Self::Error>
    where
        E: Endpoint<OAuthRequest>,
        WebError: From<E::Error>
; fn wrap<Extras>(self, extras: Extras) -> OAuthMessage<Self, Extras> { ... } }
Expand description

Describes an operation that can be performed in the presence of an Endpoint

This trait can be implemented by any type, but is very useful in Actor scenarios, where an Actor can provide an endpoint to an operation sent as a message.

Here’s how any Endpoint type can be turned into an Actor that responds to OAuthMessages:

use actix::{Actor, Context, Handler};
use oxide_auth::endpoint::Endpoint;
use oxide_auth_actix::OAuthOperation;

pub struct MyEndpoint {
    // Define your endpoint...
}

impl Endpoint<OAuthRequest> for MyEndpoint {
    // Implement your endpoint...
}

// Implement Actor
impl Actor for MyEndpoint {
    type Context = Context<Self>;
}

// Handle incoming OAuthMessages
impl<Op, Ext> Handler<OAuthMessage<Op, Ext>> for MyEndpoint
where
    Op: OAuthOperation,
{
    type Result = Result<Op::Item, Op::Error>;

    fn handle(&mut self, msg: OAuthMessage<Op, Ext>, _: &mut Self::Context) -> Self::Result {
        let (op, _) = msg.into_inner();

        op.run(self)
    }
}

By additionally specifying a type for Extras, more advanced patterns can be used

type Ext = Option<MyCustomSolicitor>;

// Handle incoming OAuthMessages
impl<Op> Handler<OAuthMessage<Op, Ext>> for MyEndpoint
where
    Op: OAuthOperation,
{
    type Result = Result<Op::Item, Op::Error>;

    fn handle(&mut self, msg: OAuthMessage<Op, Ext>, _: &mut Self::Context) -> Self::Result {
        let (op, ext) = msg.into_inner();

        op.run(self.with_my_custom_solicitor(ext))
    }
}

Associated Types

The success-type produced by an OAuthOperation

The error type produced by an OAuthOperation

Required methods

Performs the oxide operation with the provided endpoint

Provided methods

Turn an OAuthOperation into a Message to send to an actor

Implementors