intial dockerization

This commit is contained in:
2022-12-17 01:52:19 +00:00
parent 0e2aef1941
commit abdcd45057
10 changed files with 84 additions and 7 deletions

View File

@@ -23,7 +23,11 @@ CLIENT_SECRET = os.environ.get('CLIENT_SECRET', None)
if CLIENT_SECRET is None:
raise ValueError("CLIENT_SECRET cannot be None, set using environment variable")
db = Db('localhost', 6379, 0, CLIENT_ID, CLIENT_SECRET)
BASE_URL = os.environ.get('BASE_URL', None)
if BASE_URL is None:
raise ValueError("BASE_URL cannot be None, set using environtment variable")
db = Db('redis', 6379, 0, CLIENT_ID, CLIENT_SECRET)
SPOTIFY_AUTHORIZE_ENDPOINT = os.environ.get('SPOTIFY_AUTHORIZE_ENDPOINT', 'https://accounts.spotify.com/authorize?')
SPOTIFY_TOKEN_ENDPOINT = os.environ.get('SPOTIFY_AUTHORIZE_ENDPOINT', 'https://accounts.spotify.com/api/token')
@@ -60,9 +64,10 @@ def index():
loginurl = SPOTIFY_AUTHORIZE_ENDPOINT + urllib.parse.urlencode({
'client_id': CLIENT_ID,
'scope': SCOPES,
'redirect_uri': 'http://localhost:5000' + url_for('cb'),
'redirect_uri': BASE_URL + url_for('cb'),
'response_type': 'code'
})
}),
message = { 'type':'', 'text': ''}
))
resp.set_cookie(
'user_secret',
@@ -130,7 +135,7 @@ def cb():
data = {
'code': spotify_code,
'grant_type': 'authorization_code',
'redirect_uri': 'http://localhost:5000' + url_for('cb'),
'redirect_uri': BASE_URL+ url_for('cb'),
}
headers = {
'Authorization': f'Basic {authstring}',
@@ -139,6 +144,7 @@ def cb():
token_rq = rq.post(f"{SPOTIFY_TOKEN_ENDPOINT}", data = data, headers = headers)
if token_rq.status_code != rq.codes.ok:
print(f"getting token failed {token_rq.text=}")
return render_template("index_authorised.html", message={
'type': 'error',
'text': f"unable to authenticate with spotify. please try again later."
@@ -151,6 +157,7 @@ def cb():
me_rq = rq.get(f"{SPOTIFY_API_ENDPOINT}/me", headers = { 'Authorization': f"Bearer {spotify_token}" })
if me_rq.status_code != 200:
print(f"getting user info failed {me_rq.text=}")
return render_template("index_authorised.html", message={
'type': 'error',
'text': f"unable to authenticate with spotify. please try again later."

View File

@@ -1 +0,0 @@
../../common/