Struct twitch_oauth2_auth_flow::TwitchAuthHook [−][src]
pub struct TwitchAuthHook<C> { /* fields omitted */ }
Expand description
Token generator using OAuth authorization code flow
Spins up a small webserver that listens for a response from the user after they are redirected to the redirect URL by twitch.
See [auth_flow
] for a more integrated way of using this.
Make a new TwitchAuthHook
and call generate_url()
and make the user navigate to the url.
Retrieve the token with receive_auth_token
.
Example
use twitch_oauth2_auth_flow::TwitchAuthHook; use twitch_oauth2::{TwitchToken, UserToken, Scope}; use url::Url; let mut hook = TwitchAuthHook::new( twitch_oauth2::client::surf_http_client, // or twitch_oauth2::client::reqwest_http_client "my_client_id".to_string(), "my_client_secret".to_string(), vec![Scope::ChatRead, Scope::ChatEdit, Scope::ChannelModerate, Scope::ModerationRead], Url::parse("http://localhost:8081/twitch/token")?, )?; let (url, _) = hook.generate_url(); give_url_to_user(url); let token = hook.receive_auth_token();
Implementations
impl<RE, C, F> TwitchAuthHook<C> where
RE: Error + Send + Sync + 'static,
C: Copy + FnOnce(HttpRequest) -> F,
F: Future<Output = Result<HttpResponse, RE>>,
[src]
impl<RE, C, F> TwitchAuthHook<C> where
RE: Error + Send + Sync + 'static,
C: Copy + FnOnce(HttpRequest) -> F,
F: Future<Output = Result<HttpResponse, RE>>,
[src]pub fn new(
client: C,
client_id: String,
client_secret: String,
scopes: impl Into<Option<Vec<Scope>>>,
redirect_url: Url
) -> Result<TwitchAuthHook<C>, HookError<RE>>
[src]
pub fn new(
client: C,
client_id: String,
client_secret: String,
scopes: impl Into<Option<Vec<Scope>>>,
redirect_url: Url
) -> Result<TwitchAuthHook<C>, HookError<RE>>
[src]Construct a new TwitchAuthHook
pub fn generate_url(&mut self) -> (Url, CsrfToken)
[src]
pub fn generate_url(&mut self) -> (Url, CsrfToken)
[src]Generate the url and csrf token associated with this TwitchAuthHook
pub fn set_port(&mut self, port: u16)
[src]
pub fn set_port(&mut self, port: u16)
[src]Override the implicit port for the server as given by the redirect url.
Useful if the application is behind a reverse-proxy
pub async fn receive_auth_token(self) -> Result<UserToken, HookError<RE>>
[src]
pub async fn receive_auth_token(self) -> Result<UserToken, HookError<RE>>
[src]Spin up a server to retrieve the token from the user.
This token will only be valid for around 4 hours, but you can refresh the token with UserToken::refresh_token
Auto Trait Implementations
impl<C> RefUnwindSafe for TwitchAuthHook<C> where
C: RefUnwindSafe,
C: RefUnwindSafe,
impl<C> Send for TwitchAuthHook<C> where
C: Send,
C: Send,
impl<C> Sync for TwitchAuthHook<C> where
C: Sync,
C: Sync,
impl<C> Unpin for TwitchAuthHook<C> where
C: Unpin,
C: Unpin,
impl<C> UnwindSafe for TwitchAuthHook<C> where
C: UnwindSafe,
C: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<T> WithSubscriber for T
[src]
impl<T> WithSubscriber for T
[src]fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
fn with_current_subscriber(self) -> WithDispatch<Self>
[src]
fn with_current_subscriber(self) -> WithDispatch<Self>
[src]Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more