Skip to content

Commit

Permalink
feat(api_key): GetToken.api_key()
Browse files Browse the repository at this point in the history
Allows to get API keys in case there is no known scope.
There might be alterations to this, as I am unsure how it's supposed
to be implemented.
  • Loading branch information
Byron committed Mar 16, 2015
1 parent 3d1678d commit 0710d31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "yup-oauth2"
version = "0.2.3"
version = "0.3.0"
authors = ["Sebastian Thiel <[email protected]>"]
repository = "https://github.com/Byron/yup-oauth2"
description = "A partial oauth2 implementation, providing the 'device' authorization flow"
Expand Down
11 changes: 11 additions & 0 deletions src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ pub struct Authenticator<D, S, C, NC> {
}

/// 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<Token>
where T: Str + Ord,
I: IntoIterator<Item=&'b T>;

fn api_key(&mut self) -> Option<String>;
}

impl<D, S, C, NC> Authenticator<D, S, C, NC>
Expand Down Expand Up @@ -245,6 +249,13 @@ impl<D, S, C, NC> GetToken for Authenticator<D, S, C, NC>
},
}
}

fn api_key(&mut self) -> Option<String> {
if self.secret.client_id.len() == 0 {
return None
}
Some(self.secret.client_id.clone())
}
}


Expand Down

0 comments on commit 0710d31

Please sign in to comment.