From c74bf0caaf4512c90fff60ea2900f8651cc3fe02 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Mon, 3 Feb 2025 21:40:42 -0500 Subject: [PATCH] Add Auth Code up until "code" is returned --- README | 7 +++++++ server.pl | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 server.pl diff --git a/README b/README index c136cf0..a33a4ec 100644 --- a/README +++ b/README @@ -1,3 +1,10 @@ # spotilist Spotify Playlist Exporter + +## Dependencies + +On OpenBSD 7.6 the following packages are required: + +- p5-libwww +- p5-LWP-Protocol-https diff --git a/server.pl b/server.pl new file mode 100644 index 0000000..cb55c31 --- /dev/null +++ b/server.pl @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Mojolicious::Lite; + +my $CLIENT_ID = $ENV{SPOTIFY_CLIENT_ID}; +my $CLIENT_SECRET = $ENV{SPOTIFY_CLIENT_SECRET}; +if (!$CLIENT_ID || !$CLIENT_SECRET) { + die "Spotify Env Vars not set\n"; +} + +my $AUTH_URL = "https://accounts.spotify.com/authorize" + . "?client_id=$CLIENT_ID" + . "&response_type=code" + . "&redirect_uri=http://localhost:3000/auth" + . "&scope=playlist-read-private&playlist-read-collaborative" + . "&state=" . int(rand() * 100); + +get '/' => sub { + my $c = shift; + $c->render( + template => "index", + AUTH_URL => $AUTH_URL, + ); +}; + +get 'auth' => sub { + my $c = shift; + $c->render(text => "Your code is:\n" . $c->param("code")); +}; + +app->start; + +__DATA__ + +@@index.html.ep +

Spotify Playlist Exporter

+

Hello and welcome to the Spotify Playlist Exporter!

+

To start, first log in to Spotify and authorize this +app by clicking the link below:

+> +Authorize + -- libgit2 1.8.1