pub struct SpotifyAuth {
pub client_id: String,
pub client_secret: String,
pub response_type: String,
pub redirect_uri: Url,
pub state: String,
pub scope: Vec<SpotifyScope>,
pub show_dialog: bool,
}
Expand description
Spotify Authentication
This struct follows the parameters given at this link.
§Example
// Create a new spotify auth object with the scope "Streaming" using the ``new_from_env`` function.
// This object can then be converted into the auth url needed to gain a callback for the token.
let auth = SpotifyAuth::new_from_env("code".into(), vec![SpotifyScope::Streaming], false);
Fields§
§client_id: String
The Spotify Application Client ID
client_secret: String
The Spotify Application Client Secret
response_type: String
Required by the Spotify API.
redirect_uri: Url
The URI to redirect to after the user grants or denies permission.
state: String
A random generated string that can be useful for correlating requests and responses.
scope: Vec<SpotifyScope>
Vec of Spotify Scopes.
show_dialog: bool
Whether or not to force the user to approve the app again if they’ve already done so.
Implementations§
Source§impl SpotifyAuth
Conversion and helper functions for SpotifyAuth.
impl SpotifyAuth
Conversion and helper functions for SpotifyAuth.
Sourcepub fn new(
client_id: String,
client_secret: String,
response_type: String,
redirect_uri: String,
scope: Vec<SpotifyScope>,
show_dialog: bool,
) -> Self
pub fn new( client_id: String, client_secret: String, response_type: String, redirect_uri: String, scope: Vec<SpotifyScope>, show_dialog: bool, ) -> Self
Generate a new SpotifyAuth structure from values in memory.
This function loads SPOTIFY_CLIENT_ID
and SPOTIFY_REDIRECT_ID
from values given in
function parameters.
This function also automatically generates a state value of length 20 using a random string generator.
§Example
// SpotifyAuth with the scope "Streaming".
let auth = SpotifyAuth::new("00000000000".into(), "secret".into(), "code".into(), "http://localhost:8000/callback".into(), vec![SpotifyScope::Streaming], false);
Sourcepub fn new_from_env(
response_type: String,
scope: Vec<SpotifyScope>,
show_dialog: bool,
) -> Self
pub fn new_from_env( response_type: String, scope: Vec<SpotifyScope>, show_dialog: bool, ) -> Self
Generate a new SpotifyAuth structure from values in the environment.
This function loads SPOTIFY_CLIENT_ID
and SPOTIFY_REDIRECT_ID
from the environment.
This function also automatically generates a state value of length 20 using a random string generator.
§Example
// SpotifyAuth with the scope "Streaming".
let auth = SpotifyAuth::new_from_env("code".into(), vec![SpotifyScope::Streaming], false);
Sourcepub fn scope_into_string(&self) -> String
pub fn scope_into_string(&self) -> String
Concatenate the scope vector into a string needed for the authorization URL.
§Example
// Default SpotifyAuth with the scope "Streaming".
let auth = SpotifyAuth::new("00000000000".into(), "secret".into(), "code".into(), "http://localhost:8000/callback".into(), vec![SpotifyScope::Streaming], false);
Convert the SpotifyAuth struct into the authorization URL.
More information on this URL can be found here.
§Example
// Default SpotifyAuth with the scope "Streaming" converted into the authorization URL.
let auth = SpotifyAuth::new("00000000000".into(), "secret".into(), "code".into(), "http://localhost:8000/callback".into(), vec![SpotifyScope::Streaming], false)
.authorize_url().unwrap();
Trait Implementations§
Source§impl Default for SpotifyAuth
Implementation of Default for SpotifyAuth.
impl Default for SpotifyAuth
Implementation of Default for SpotifyAuth.
If CLIENT_ID
is not found in the .env
in the project directory it will default to INVALID_ID
.
If REDIRECT_ID
is not found in the .env
in the project directory it will default to http://localhost:8000/callback
.
This implementation automatically generates a state value of length 20 using a random string generator.