Ensure a client ID is present

This commit is contained in:
Roderick van Domburg 2022-01-22 21:27:56 +01:00
parent 0822af0328
commit 0630586cd6
No known key found for this signature in database
GPG key ID: FE2585E713F9F30A

View file

@ -65,6 +65,11 @@ impl TokenProvider {
// scopes must be comma-separated
pub async fn get_token(&self, scopes: &str) -> Result<Token, Error> {
let client_id = self.session().client_id();
if client_id.is_empty() {
return Err(Error::invalid_argument("Client ID cannot be empty"));
}
if let Some(index) = self.find_token(scopes.split(',').collect()) {
let cached_token = self.lock(|inner| inner.tokens[index].clone());
if cached_token.is_expired() {
@ -82,7 +87,7 @@ impl TokenProvider {
let query_uri = format!(
"hm://keymaster/token/authenticated?scope={}&client_id={}&device_id={}",
scopes,
self.session().client_id(),
client_id,
self.session().device_id(),
);
let request = self.session().mercury().get(query_uri)?;