Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth process made by a struct, allowing customization options. #1462

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [connect] Add `pause` parameter to `Spirc::disconnect` method (breaking)
- [playback] Add `track` field to `PlayerEvent::RepeatChanged` (breaking)
- [core] Add `request_with_options` and `request_with_protobuf_and_options` to `SpClient`
- [oauth] Add `OAuthClient` and `OAuthClientBuilder` structs to achieve a more customizable login process

### Fixed

Expand All @@ -39,6 +40,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [connect] Handle transfer of playback with empty "uri" field
- [connect] Correctly apply playing/paused state when transferring playback

### Deprecated

- [oauth] `get_access_token()` function marked for deprecation

### Removed

- [core] Removed `get_canvases` from SpClient (breaking)
Expand Down Expand Up @@ -76,7 +81,7 @@ backend for Spotify Connect discovery.
## [0.5.0] - 2024-10-15

This version is be a major departure from the architecture up until now. It
focuses on implementing the "new Spotify API". This means moving large parts
focuses on implementing the "new Spotify API". This means moving large parts
of the Spotify protocol from Mercury to HTTP. A lot of this was reverse
engineered before by @devgianlu of librespot-java. It was long overdue that we
started implementing it too, not in the least because new features like the
Expand Down Expand Up @@ -219,14 +224,17 @@ to offer. But, unless anything big comes up, it is also intended as the last
release to be based on the old API. Happy listening.

### Changed

- [playback] `pipe`: Better error handling
- [playback] `subprocess`: Better error handling

### Added

- [core] `apresolve`: Blacklist ap-gew4 and ap-gue1 access points that cause channel errors
- [playback] `pipe`: Implement stop

### Fixed

- [main] fix `--opt=value` line argument logging
- [playback] `alsamixer`: make `--volume-ctrl fixed` work as expected when combined with `--mixer alsa`

Expand All @@ -235,9 +243,11 @@ release to be based on the old API. Happy listening.
This release fixes dependency issues when installing from crates.

### Changed

- [chore] The MSRV is now 1.56

### Fixed

- [playback] Fixed dependency issues when installing from crate

## [0.4.0] - 2022-05-21
Expand All @@ -253,6 +263,7 @@ Targeting that major effort for a v0.5 release sometime, we intend to maintain
v0.4.x as a stable branch until then.

### Changed

- [chore] The MSRV is now 1.53
- [contrib] Hardened security of the `systemd` service units
- [core] `Session`: `connect()` now returns the long-term credentials
Expand All @@ -265,6 +276,7 @@ v0.4.x as a stable branch until then.
- [playback] `Sink`: `write()` now receives ownership of the packet (breaking)

### Added

- [main] Enforce reasonable ranges for option values (breaking)
- [main] Add the ability to parse environment variables
- [main] Log now emits warning when trying to use options that would otherwise have no effect
Expand All @@ -277,6 +289,7 @@ v0.4.x as a stable branch until then.
- [playback] `pulseaudio`: set values to: `PULSE_PROP_application.version`, `PULSE_PROP_application.process.binary`, `PULSE_PROP_stream.description`, `PULSE_PROP_media.software` and `PULSE_PROP_media.role` environment variables (user set env var values take precedence) (breaking)

### Fixed

- [connect] Don't panic when activating shuffle without previous interaction
- [core] Removed unsafe code (breaking)
- [main] Fix crash when built with Avahi support but Avahi is locally unavailable
Expand All @@ -287,20 +300,24 @@ v0.4.x as a stable branch until then.
- [playback] `alsa`: make `--volume-range` overrides apply to Alsa softvol controls

### Removed

- [playback] `alsamixer`: previously deprecated options `mixer-card`, `mixer-name` and `mixer-index` have been removed

## [0.3.1] - 2021-10-24

### Changed

- Include build profile in the displayed version information
- [playback] Improve dithering CPU usage by about 33%

### Fixed

- [connect] Partly fix behavior after last track of an album/playlist

## [0.3.0] - 2021-10-13

### Added

- [discovery] The crate `librespot-discovery` for discovery in LAN was created. Its functionality was previously part of `librespot-connect`.
- [playback] Add support for dithering with `--dither` for lower requantization error (breaking)
- [playback] Add `--volume-range` option to set dB range and control `log` and `cubic` volume control curves
Expand All @@ -309,6 +326,7 @@ v0.4.x as a stable branch until then.
- [playback] Add `--normalisation-gain-type auto` that switches between album and track automatically

### Changed

- [audio, playback] Moved `VorbisDecoder`, `VorbisError`, `AudioPacket`, `PassthroughDecoder`, `PassthroughError`, `DecoderError`, `AudioDecoder` and the `convert` module from `librespot-audio` to `librespot-playback`. The underlying crates `vorbis`, `librespot-tremor`, `lewton` and `ogg` should be used directly. (breaking)
- [audio, playback] Use `Duration` for time constants and functions (breaking)
- [connect, playback] Moved volume controls from `librespot-connect` to `librespot-playback` crate
Expand All @@ -325,17 +343,20 @@ v0.4.x as a stable branch until then.
- [playback] `player`: default normalisation type is now `auto`

### Deprecated

- [connect] The `discovery` module was deprecated in favor of the `librespot-discovery` crate
- [playback] `alsamixer`: renamed `mixer-card` to `alsa-mixer-device`
- [playback] `alsamixer`: renamed `mixer-name` to `alsa-mixer-control`
- [playback] `alsamixer`: renamed `mixer-index` to `alsa-mixer-index`

### Removed

- [connect] Removed no-op mixer started/stopped logic (breaking)
- [playback] Removed `with-vorbis` and `with-tremor` features
- [playback] `alsamixer`: removed `--mixer-linear-volume` option, now that `--volume-ctrl {linear|log}` work as expected on Alsa

### Fixed

- [connect] Fix step size on volume up/down events
- [connect] Fix looping back to the first track after the last track of an album or playlist
- [playback] Incorrect `PlayerConfig::default().normalisation_threshold` caused distortion when using dynamic volume normalisation downstream
Expand Down
60 changes: 60 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions oauth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ edition = "2021"
[dependencies]
log = "0.4"
oauth2 = "4.4"
open = "5.3"
thiserror = "2.0"
url = "2.2"
veil = "0.2"

[dev-dependencies]
env_logger = { version = "0.11.2", default-features = false, features = ["color", "humantime", "auto-color"] }
tokio = { version = "1.43.0", features = ["rt-multi-thread", "macros"] }
32 changes: 0 additions & 32 deletions oauth/examples/oauth.rs

This file was deleted.

65 changes: 65 additions & 0 deletions oauth/examples/oauth_async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use std::env;

use librespot_oauth::OAuthClientBuilder;

const SPOTIFY_CLIENT_ID: &str = "65b708073fc0480ea92a077233ca87bd";
const SPOTIFY_REDIRECT_URI: &str = "http://127.0.0.1:8898/login";

const RESPONSE: &str = r#"
<!doctype html>
<html>
<body>
<h1>Return to your app!</h1>
</body>
</html>
"#;

#[tokio::main]
async fn main() {
let mut builder = env_logger::Builder::new();
builder.parse_filters("librespot=trace");
builder.init();

let args: Vec<_> = env::args().collect();
let (client_id, redirect_uri, scopes) = if args.len() == 4 {
// You can use your own client ID, along with it's associated redirect URI.
(
args[1].as_str(),
args[2].as_str(),
args[3].split(',').collect::<Vec<&str>>(),
)
} else if args.len() == 1 {
(SPOTIFY_CLIENT_ID, SPOTIFY_REDIRECT_URI, vec!["streaming"])
} else {
eprintln!("Usage: {} [CLIENT_ID REDIRECT_URI SCOPES]", args[0]);
return;
};

let client = match OAuthClientBuilder::new(client_id, redirect_uri, scopes)
.open_in_browser()
.with_custom_message(RESPONSE)
.build()
{
Ok(client) => client,
Err(err) => {
eprintln!("Unable to build an OAuth client: {}", err);
return;
}
};

let refresh_token = match client.get_access_token_async().await {
photovoltex marked this conversation as resolved.
Show resolved Hide resolved
Ok(token) => {
println!("OAuth Token: {token:#?}");
token.refresh_token
}
Err(err) => {
println!("Unable to get OAuth Token: {err}");
return;
}
};

match client.refresh_token_async(&refresh_token).await {
Ok(token) => println!("New refreshed OAuth Token: {token:#?}"),
Err(err) => println!("Unable to get refreshed OAuth Token: {err}"),
}
}
Loading