Skip to content

Commit

Permalink
Get token with client (#1385)
Browse files Browse the repository at this point in the history
Co-authored-by: fivebanger <[email protected]>
  • Loading branch information
fivebanger and fivebanger authored Oct 30, 2024
1 parent f96f36c commit 1d3771a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token, Error> {
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<Token, Error> {
if client_id.is_empty() {
return Err(Error::invalid_argument("Client ID cannot be empty"));
}
Expand Down

0 comments on commit 1d3771a

Please sign in to comment.