feat(api_key): GetToken.api_key()

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.
This commit is contained in:
Sebastian Thiel
2015-03-16 13:41:19 +01:00
parent 3d1678daea
commit 0710d310f8
2 changed files with 12 additions and 1 deletions

View File

@@ -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>
@@ -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())
}
}