From 1d3771a83bd94025ee16a7367a556bfec7e4e4cc Mon Sep 17 00:00:00 2001 From: fivebanger <14848554+fivebanger@users.noreply.github.com> Date: Wed, 30 Oct 2024 20:24:01 +0100 Subject: [PATCH] Get token with client (#1385) Co-authored-by: fivebanger --- CHANGELOG.md | 1 + core/src/token.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc6985b4..4680fc7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- [core] Add `get_token_with_client_id()` to get a token for a specific client ID - [core] Add `login` (mobile) and `auth_token` retrieval via login5 - [core] Add `OS` and `os_version` to `config.rs` - [discovery] Added a new MDNS/DNS-SD backend which connects to Avahi via D-Bus. diff --git a/core/src/token.rs b/core/src/token.rs index 946367c3..445b8aeb 100644 --- a/core/src/token.rs +++ b/core/src/token.rs @@ -58,9 +58,20 @@ impl TokenProvider { }) } + // Not all combinations of scopes and client ID are allowed. + // Depending on the client ID currently used, the function may return an error for specific scopes. + // In this case get_token_with_client_id() can be used, where an appropriate client ID can be provided. // scopes must be comma-separated pub async fn get_token(&self, scopes: &str) -> Result { let client_id = self.session().client_id(); + self.get_token_with_client_id(scopes, &client_id).await + } + + pub async fn get_token_with_client_id( + &self, + scopes: &str, + client_id: &str, + ) -> Result { if client_id.is_empty() { return Err(Error::invalid_argument("Client ID cannot be empty")); }