adding auth
This commit is contained in:
@@ -9,27 +9,52 @@ import (
|
||||
|
||||
"adam-french.co.uk/backend/handlers"
|
||||
"adam-french.co.uk/backend/services"
|
||||
|
||||
spotifyauth "github.com/zmb3/spotify/v2/auth"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db, err := services.InitDatabase()
|
||||
db_user := os.Getenv("POSTGRES_USER")
|
||||
db_password := os.Getenv("POSTGRES_PASSWORD")
|
||||
dbname := os.Getenv("POSTGRES_DB")
|
||||
db_host := os.Getenv("POSTGRES_HOST")
|
||||
db_port := os.Getenv("POSTGRES_PORT")
|
||||
db_config := services.SQLConfig{User: db_user, Password: db_password, DBName: dbname, Host: db_host, Port: db_port}
|
||||
db, err := services.InitDatabase(db_config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
spotify_client, err := services.InitSpotify()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
r := gin.Default()
|
||||
store := handlers.Store{DB: db, SpotifyClient: spotify_client}
|
||||
|
||||
authState := os.Getenv("SPOTIFY_AUTH_STATE")
|
||||
redirectURL := os.Getenv("SPOTIFY_REDIRECT_URI")
|
||||
// clientID := os.Getenv("SPOTIFY_CLIENT_ID")
|
||||
// clientSecret := os.Getenv("SPOTIFY_CLIENT_SECRET")
|
||||
|
||||
auth := spotifyauth.New(
|
||||
spotifyauth.WithRedirectURL(redirectURL),
|
||||
spotifyauth.WithScopes(
|
||||
spotifyauth.ScopeUserReadPlaybackState,
|
||||
spotifyauth.ScopeUserReadCurrentlyPlaying,
|
||||
),
|
||||
)
|
||||
|
||||
fmt.Println("Authenticate spotify with:")
|
||||
fmt.Println(auth.AuthURL(authState))
|
||||
|
||||
store := handlers.Store{DB: db, SpotifyAuth: auth, SpotifyToken: nil}
|
||||
|
||||
r.GET("/posts", store.GetPosts)
|
||||
r.POST("/posts", store.CreatePost)
|
||||
r.PUT("/posts/:id", store.UpdatePost)
|
||||
|
||||
r.GET("/spotify", store.ListeningTo)
|
||||
r.GET("/callback", store.CompleteAuth)
|
||||
// r.GET("/spotify", store.ListeningTo)
|
||||
// r.POST("/spotify", store.SendSong)
|
||||
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user