mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-08 21:37:58 -05:00
27
spt/auth.go
27
spt/auth.go
@@ -8,7 +8,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
_auth "github.com/zmb3/spotify/v2/auth"
|
_auth "github.com/zmb3/spotify/v2/auth"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@@ -17,6 +19,24 @@ import (
|
|||||||
"github.com/zmb3/spotify/v2"
|
"github.com/zmb3/spotify/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Taken from: https://gist.github.com/hyg/9c4afcd91fe24316cbf0l
|
||||||
|
func openbrowser(url string) error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
err = exec.Command("xdg-open", url).Start()
|
||||||
|
case "windows":
|
||||||
|
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
||||||
|
case "darwin":
|
||||||
|
err = exec.Command("open", url).Start()
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("unsupported platform")
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
redirectURI = "http://localhost:8080/callback"
|
redirectURI = "http://localhost:8080/callback"
|
||||||
scopes = []string{
|
scopes = []string{
|
||||||
@@ -85,8 +105,11 @@ func InitClient() error {
|
|||||||
}()
|
}()
|
||||||
url := auth.AuthURL(state)
|
url := auth.AuthURL(state)
|
||||||
|
|
||||||
fmt.Println("Please log in to Spotify by visiting the following page in your browser: ")
|
fmt.Println("Please log in to Spotify through the browser.")
|
||||||
fmt.Println(url)
|
if err := openbrowser(url); err != nil {
|
||||||
|
fmt.Printf("Error opening the default browsers: %s\nPlease open the following link Manually:\n", err.Error())
|
||||||
|
fmt.Println(url)
|
||||||
|
}
|
||||||
|
|
||||||
// wait for auth to complete
|
// wait for auth to complete
|
||||||
payload := <-ch
|
payload := <-ch
|
||||||
|
|||||||
Reference in New Issue
Block a user