pub trait OAuthOperation: Sized + 'static {
    type Item: 'static;
    type Error: Debug + 'static;

    // Required method
    fn run<E>(self, endpoint: E) -> Result<Self::Item, Self::Error>
       where E: Endpoint<OAuthRequest>,
             WebError: From<E::Error>;

    // Provided method
    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))
    }
}

Required Associated Types§

source

type Item: 'static

The success-type produced by an OAuthOperation

source

type Error: Debug + 'static

The error type produced by an OAuthOperation

Required Methods§

source

fn run<E>(self, endpoint: E) -> Result<Self::Item, Self::Error>

Performs the oxide operation with the provided endpoint

Provided Methods§

source

fn wrap<Extras>(self, extras: Extras) -> OAuthMessage<Self, Extras>

Turn an OAuthOperation into a Message to send to an actor

Object Safety§

This trait is not object safe.

Implementors§