From d34229bc3e495d2927415f408b18aec51a4574e2 Mon Sep 17 00:00:00 2001 From: David Blajda Date: Tue, 18 Dec 2018 05:06:05 +0000 Subject: Implement auth client and auth barrier --- src/helix/namespaces/auth.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ src/helix/namespaces/clips.rs | 4 ++-- src/helix/namespaces/mod.rs | 1 + 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/helix/namespaces/auth.rs (limited to 'src/helix/namespaces') diff --git a/src/helix/namespaces/auth.rs b/src/helix/namespaces/auth.rs new file mode 100644 index 0000000..8ad7956 --- /dev/null +++ b/src/helix/namespaces/auth.rs @@ -0,0 +1,43 @@ +use futures::future::Future; +use std::collections::BTreeMap; +use super::super::models::Credentials; +use super::super::Client; +const ID_DOMAIN: &'static str = "id.twitch.tv"; +use super::super::Namespace; + +pub struct Auth {} +type AuthNamespace = Namespace; + +impl AuthNamespace { + pub fn client_credentials(self, secret: &str) + -> ApiRequest { + use self::client_credentials; + client_credentials(self.client, secret) + } +} + +impl Client { + pub fn auth(&self) -> AuthNamespace { + AuthNamespace::new(self) + } +} + +use super::super::ApiRequest; +use reqwest::Method; + +//TODO: Implement scopes +pub fn client_credentials(client: Client, secret: &str) + -> ApiRequest { + + let url = + String::from("https://") + + ID_DOMAIN + "/oauth2/token"; + + let mut params = BTreeMap::new(); + params.insert("client_id".to_owned(), client.id().to_owned()); + params.insert("client_secret".to_owned(), secret.to_owned()); + params.insert("grant_type".to_owned(), "client_credentials".to_owned()); + params.insert("scope".to_owned(), "".to_owned()); + + ApiRequest::new(url, params, client, Method::POST) +} diff --git a/src/helix/namespaces/clips.rs b/src/helix/namespaces/clips.rs index 351f006..ac820e8 100644 --- a/src/helix/namespaces/clips.rs +++ b/src/helix/namespaces/clips.rs @@ -23,7 +23,7 @@ impl Client { } use super::super::ApiRequest; - +use reqwest::Method; pub fn clip(client: Client, id: &str) -> ApiRequest> @@ -34,5 +34,5 @@ pub fn clip(client: Client, id: &str) let params = BTreeMap::new(); - ApiRequest::new( url, params, client) + ApiRequest::new(url, params, client, Method::GET) } diff --git a/src/helix/namespaces/mod.rs b/src/helix/namespaces/mod.rs index ad73aa3..d1c44bd 100644 --- a/src/helix/namespaces/mod.rs +++ b/src/helix/namespaces/mod.rs @@ -1,3 +1,4 @@ pub mod clips; pub mod users; pub mod videos; +pub mod auth; -- cgit v1.2.3