def authorize():
    try:
        conf = tk.config_from_file(config_file, return_refresh=True)
        token = tk.refresh_pkce_token(conf[0], conf[3])
        tk.config_to_file(config_file, conf[:3] + (token.refresh_token, ))
    except:
        client_secret = 'your_client_secret'
        redirect_uri = 'https://example.com/callback'  # Or your redirect uri
        conf = (client_id, client_secret, redirect_uri)
        token = tk.prompt_for_pkce_token(client_id,
                                         redirect_uri,
                                         scope=tk.scope.every)
        tk.config_to_file(config_file, conf + (token.refresh_token, ))
    return tk.Spotify(token)
import tekore as tk
import os
"""
TODO Change the three fields below to your Spotify Developer Client ID, 
Client Secret, and your specified Redirect URI (access via the green 
"Edit Settings" button).
TODO Run python3 config.py to create the credentials.ini file
"""

client_id = os.environ.get("CLIENT_ID")  # TODO
client_secret = os.environ.get("CLIENT_SECRET")  # TODO
redirect_uri = "http://localhost/"

conf = (client_id, client_secret, redirect_uri)
tk.config_to_file('credentials.ini', conf)