diff --git a/Cargo.toml b/Cargo.toml index 99ea53947..9f320c41c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yup-oauth2" -version = "0.2.3" +version = "0.3.0" authors = ["Sebastian Thiel "] repository = "https://github.com/Byron/yup-oauth2" description = "A partial oauth2 implementation, providing the 'device' authorization flow" diff --git a/src/helper.rs b/src/helper.rs index 6327da915..a931031ff 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -81,10 +81,14 @@ pub struct Authenticator { } /// A provider for authorization tokens, yielding tokens valid for a given scope. +/// The `api_key()` method is an alternative in case there are no scopes or +/// if no user is involved. pub trait GetToken { fn token<'b, I, T>(&mut self, scopes: I) -> Option where T: Str + Ord, I: IntoIterator; + + fn api_key(&mut self) -> Option; } impl Authenticator @@ -245,6 +249,13 @@ impl GetToken for Authenticator }, } } + + fn api_key(&mut self) -> Option { + if self.secret.client_id.len() == 0 { + return None + } + Some(self.secret.client_id.clone()) + } }