NewAuthenticator returns a Spotify authenticator object configured with the required callback URL, client IT and client secret. An error is returned if one is encountered
()
| 14 | // NewAuthenticator returns a Spotify authenticator object configured with the required callback URL, |
| 15 | // client IT and client secret. An error is returned if one is encountered |
| 16 | func NewAuthenticator() (*spotify.Authenticator, error) { |
| 17 | r := ConfigValue(SPOTIFY_CALLBACK_URL) |
| 18 | u, err := url.Parse(r) |
| 19 | if err != nil { |
| 20 | return nil, err |
| 21 | } |
| 22 | |
| 23 | id := ConfigValue(SPOTIFY_CLIENT_ID) |
| 24 | s := ConfigValue(SPOTIFY_CLIENT_SECRET) |
| 25 | |
| 26 | auth := spotify.NewAuthenticator(u.String(), spotify.ScopeUserReadPrivate, spotify.ScopePlaylistReadPrivate, |
| 27 | spotify.ScopeUserModifyPlaybackState, spotify.ScopeUserReadPlaybackState) |
| 28 | |
| 29 | auth.SetAuthInfo(id, s) |
| 30 | |
| 31 | return &auth, nil |
| 32 | } |
| 33 | |
| 34 | // NewToken will create a new OAuth2 token request. |
| 35 | // The user will be prompted to visit a URL, and after access is granted a new OAuth2 token is returned. |