Struct SpotifyAuth

Source
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.

Source

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);
Source

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);
Source

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);
Source

pub fn authorize_url(&self) -> Result<String, SpotifyError>

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.

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.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,