-
Notifications
You must be signed in to change notification settings - Fork 123
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
[WIP] Auth restructure #207
Closed
Closed
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
05f906b
moving http to a new crate
marioortizmanero 68d625f
rspotify-http now working more or less
marioortizmanero bbbb3af
moving endpoints to respective traits
marioortizmanero 1a4487b
hit a wall with `impl`
marioortizmanero 61edf5d
it compiles... but at what cost
marioortizmanero 82f1825
format
marioortizmanero b47f273
numerous fixes
marioortizmanero 1107624
some fixes
marioortizmanero 3a0bb68
Merge with master
marioortizmanero 02c4c0c
format
marioortizmanero 8b40904
now compiling!
marioortizmanero 7ece549
fixed album example
marioortizmanero ab39089
some fixes to the examples
marioortizmanero 2c63e4c
remove old oauth file
marioortizmanero 6d152a6
fix second example
marioortizmanero 01e581f
tidy up examples, fix current_playing
marioortizmanero a825ae7
remove println
marioortizmanero 4ac19cc
fixes most examples
marioortizmanero 3ce657e
fix pagination
marioortizmanero 9112d75
all examples work now
marioortizmanero 3b41775
fix tests
marioortizmanero 17781e5
fully fix pagination
marioortizmanero bf3235a
some more fixes
marioortizmanero 12a97ef
fix clippy
marioortizmanero c87b340
i think this should fully pass CI
marioortizmanero a4ce9ef
ClientError::InvalidAuth can be removed now
marioortizmanero f7721b1
fix compilation conflicts
marioortizmanero 1651aff
add rspotify-http tests to CI
marioortizmanero 738f9de
format and add `with_token` constructor
marioortizmanero 98c0fb3
fix most documentation
marioortizmanero 2cadd88
mention pkce example
marioortizmanero 1eb5edf
fix tests
marioortizmanero d318b7f
handling more cached cases
marioortizmanero decd8c6
add comments to the code auth implementation
marioortizmanero 6603b1c
comments for the PKCE client as well
marioortizmanero b9835e8
comments for client credentials
marioortizmanero 03fb05b
move oauth utilities to the trait
marioortizmanero 060cd72
fix comment
marioortizmanero 3c94d37
comments for the traits
marioortizmanero 01e172c
remove TODO
marioortizmanero f16e148
fix webapp example
marioortizmanero 1e96b5b
move confusing read_token_cache method
marioortizmanero 599cea8
fix cli compilation
marioortizmanero 3409e60
bump url to fix warning
marioortizmanero fdafad8
fix tests
marioortizmanero 4699343
fix CI
marioortizmanero 2c93222
remove cyclic dependency
marioortizmanero e6ed136
fix last CI issue
marioortizmanero b45b0f3
add myself as an author!
marioortizmanero 0c3faed
rename: code_auth -> auth_code
marioortizmanero 7523da4
rename: CodeAuthSpotify -> AuthCodeSpotify
marioortizmanero f44d9e8
rename: CodeAuthPkceSpotify -> AuthCodePkceSpotify
marioortizmanero 1367931
rename: ClientCredentialsSpotify -> ClientCredsSpotify
marioortizmanero 8c016bc
rename: endpoints -> clients
marioortizmanero 5c1a7be
fix maybe-async/is_sync in cargo.toml
marioortizmanero 56d5c52
fix renames
marioortizmanero bc0e0e4
format
marioortizmanero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
[package] | ||
authors = ["Ramsay Leung <[email protected]>"] | ||
authors = [ | ||
"Ramsay Leung <[email protected]>", | ||
"Mario Ortiz Manero <[email protected]>" | ||
] | ||
name = "rspotify" | ||
version = "0.10.0" | ||
license = "MIT" | ||
|
@@ -13,7 +16,8 @@ edition = "2018" | |
[workspace] | ||
members = [ | ||
"rspotify-macros", | ||
"rspotify-model" | ||
"rspotify-model", | ||
"rspotify-http" | ||
] | ||
exclude = [ | ||
"examples/webapp" | ||
|
@@ -25,19 +29,23 @@ resolver = "2" | |
[dependencies] | ||
rspotify-macros = { path = "rspotify-macros", version = "0.10.0" } | ||
rspotify-model = { path = "rspotify-model", version = "0.10.0" } | ||
rspotify-http = { path = "rspotify-http", version = "0.10.0", default-features = false } | ||
|
||
### Client ### | ||
async-stream = { version = "0.3.0", optional = true } | ||
async-trait = { version = "0.1.48", optional = true } | ||
base64 = "0.13.0" | ||
chrono = { version = "0.4.13", features = ["serde", "rustc-serialize"] } | ||
derive_builder = "0.10.0" | ||
dotenv = { version = "0.15.0", optional = true } | ||
futures = { version = "0.3.8", optional = true } | ||
futures-util = "0.3.8" # TODO | ||
getrandom = "0.2.0" | ||
log = "0.4.11" | ||
maybe-async = "0.2.1" | ||
serde = { version = "1.0.115", features = ["derive"] } | ||
serde_json = "1.0.57" | ||
thiserror = "1.0.20" | ||
url = "2.2.2" | ||
webbrowser = { version = "0.5.5", optional = true } | ||
|
||
### Auth ### | ||
|
@@ -46,18 +54,6 @@ webbrowser = { version = "0.5.5", optional = true } | |
# maybe-async = "0.2.1" | ||
# thiserror = "1.0.20" | ||
|
||
### HTTP ### | ||
# Temporary until https://github.com/rust-lang/rfcs/issues/2739, for | ||
# `maybe_async`. | ||
async-trait = { version = "0.1.48", optional = true } | ||
base64 = "0.13.0" | ||
# log = "0.4.11" | ||
# maybe-async = "0.2.1" | ||
reqwest = { version = "0.11.0", default-features = false, features = ["json", "socks"], optional = true } | ||
# thiserror = "1.0.20" | ||
ureq = { version = "2.0", default-features = false, features = ["json", "cookies"], optional = true } | ||
url = "2.1.1" | ||
|
||
[dev-dependencies] | ||
env_logger = "0.8.1" | ||
tokio = { version = "1.0", features = ["rt-multi-thread", "macros"] } | ||
|
@@ -73,49 +69,44 @@ env-file = ["dotenv"] | |
### HTTP ### | ||
# Available clients. By default they don't include a TLS so that it can be | ||
# configured. | ||
client-ureq = ["ureq", "__sync"] | ||
client-reqwest = ["reqwest", "__async"] | ||
client-ureq = ["rspotify-http/client-ureq", "__sync"] | ||
client-reqwest = ["rspotify-http/client-reqwest", "__async"] | ||
|
||
# Passing the TLS features to reqwest. | ||
reqwest-default-tls = ["reqwest/default-tls"] | ||
reqwest-rustls-tls = ["reqwest/rustls-tls"] | ||
reqwest-native-tls = ["reqwest/native-tls"] | ||
reqwest-native-tls-vendored = ["reqwest/native-tls-vendored"] | ||
reqwest-default-tls = ["rspotify-http/reqwest-default-tls"] | ||
reqwest-rustls-tls = ["rspotify-http/reqwest-rustls-tls"] | ||
reqwest-native-tls = ["rspotify-http/reqwest-native-tls"] | ||
reqwest-native-tls-vendored = ["rspotify-http/reqwest-native-tls-vendored"] | ||
# Same for ureq. | ||
ureq-rustls-tls = ["ureq/tls"] | ||
ureq-rustls-tls = ["rspotify-http/ureq-rustls-tls"] | ||
|
||
# Internal features for checking async or sync compilation | ||
__async = ["async-trait", "async-stream", "futures"] | ||
__async = ["futures", "async-stream", "async-trait"] | ||
__sync = ["maybe-async/is_sync"] | ||
|
||
[package.metadata.docs.rs] | ||
# Also documenting the CLI methods | ||
features = ["cli"] | ||
|
||
[[example]] | ||
name = "album" | ||
required-features = ["env-file", "cli", "client-reqwest"] | ||
path = "examples/album.rs" | ||
|
||
[[example]] | ||
name = "current_user_recently_played" | ||
name = "client_creds" | ||
required-features = ["env-file", "cli", "client-reqwest"] | ||
path = "examples/current_user_recently_played.rs" | ||
path = "examples/client_creds.rs" | ||
|
||
[[example]] | ||
name = "oauth_tokens" | ||
name = "auth_code" | ||
required-features = ["env-file", "cli", "client-reqwest"] | ||
path = "examples/oauth_tokens.rs" | ||
path = "examples/auth_code.rs" | ||
|
||
[[example]] | ||
name = "track" | ||
name = "auth_code_pkce" | ||
required-features = ["env-file", "cli", "client-reqwest"] | ||
path = "examples/track.rs" | ||
path = "examples/auth_code_pkce.rs" | ||
|
||
[[example]] | ||
name = "tracks" | ||
name = "oauth_tokens" | ||
required-features = ["env-file", "cli", "client-reqwest"] | ||
path = "examples/tracks.rs" | ||
path = "examples/oauth_tokens.rs" | ||
|
||
[[example]] | ||
name = "with_refresh_token" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use rspotify::{ | ||
model::{AdditionalType, Country, Market}, | ||
prelude::*, | ||
scopes, AuthCodeSpotify, Credentials, OAuth, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// You can use any logger for debugging. | ||
env_logger::init(); | ||
|
||
// Set RSPOTIFY_CLIENT_ID, RSPOTIFY_CLIENT_SECRET and | ||
// RSPOTIFY_REDIRECT_URI in an .env file or export them manually: | ||
// | ||
// export RSPOTIFY_CLIENT_ID="your client_id" | ||
// export RSPOTIFY_CLIENT_SECRET="secret" | ||
// | ||
// These will then be read with `from_env`. | ||
// | ||
// Otherwise, set client_id and client_secret explictly: | ||
// | ||
// ``` | ||
// let creds = Credentials { | ||
// id: "this-is-my-client-id".to_string(), | ||
// secret: "this-is-my-client-secret".to_string() | ||
// }; | ||
// ``` | ||
let creds = Credentials::from_env().unwrap(); | ||
|
||
// Or set the redirect_uri explictly: | ||
// | ||
// ``` | ||
// let oauth = OAuth { | ||
// redirect_uri: "http://localhost:8888/callback".to_string(), | ||
// scope: scopes!("user-read-recently-played"), | ||
// ..Default::default(), | ||
// }; | ||
// ``` | ||
let oauth = OAuth::from_env(scopes!("user-read-currently-playing")).unwrap(); | ||
|
||
let mut spotify = AuthCodeSpotify::new(creds, oauth); | ||
|
||
// Obtaining the access token | ||
let url = spotify.get_authorize_url(false).unwrap(); | ||
spotify.prompt_for_token(&url).await.unwrap(); | ||
|
||
// Running the requests | ||
let market = Market::Country(Country::Spain); | ||
let additional_types = [AdditionalType::Episode]; | ||
let artists = spotify | ||
.current_playing(Some(&market), Some(&additional_types)) | ||
.await; | ||
|
||
println!("Response: {:?}", artists); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use rspotify::{prelude::*, scopes, AuthCodePkceSpotify, Credentials, OAuth}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
// You can use any logger for debugging. | ||
env_logger::init(); | ||
|
||
// Set RSPOTIFY_CLIENT_ID, RSPOTIFY_CLIENT_SECRET and | ||
// RSPOTIFY_REDIRECT_URI in an .env file or export them manually: | ||
// | ||
// export RSPOTIFY_CLIENT_ID="your client_id" | ||
// export RSPOTIFY_CLIENT_SECRET="secret" | ||
// | ||
// These will then be read with `from_env`. | ||
// | ||
// Otherwise, set client_id and client_secret explictly: | ||
// | ||
// ``` | ||
// let creds = Credentials { | ||
// id: "this-is-my-client-id".to_string(), | ||
// secret: "this-is-my-client-secret".to_string() | ||
// }; | ||
// ``` | ||
let creds = Credentials::from_env().unwrap(); | ||
|
||
// Or set the redirect_uri explictly: | ||
// | ||
// ``` | ||
// let oauth = OAuth { | ||
// redirect_uri: "http://localhost:8888/callback".to_string(), | ||
// scope: scopes!("user-read-recently-played"), | ||
// ..Default::default(), | ||
// }; | ||
// ``` | ||
let oauth = OAuth::from_env(scopes!("user-read-recently-played")).unwrap(); | ||
|
||
let mut spotify = AuthCodePkceSpotify::new(creds, oauth); | ||
|
||
// Obtaining the access token | ||
let url = spotify.get_authorize_url().unwrap(); | ||
spotify.prompt_for_token(&url).await.unwrap(); | ||
|
||
// Running the requests | ||
let history = spotify.current_playback(None, None::<Vec<_>>).await; | ||
|
||
println!("Response: {:?}", history); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't
rspotify-http
enable by default?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we need to manually specify which client to use. Perhaps
rspotify-http
shouldn't enable clients by default, and that should be done byrspotify
itself?