mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 01:03:53 +00:00
Allow for total headless mode by instructing the user to open the URL in a browser. (#528)
* Allow for total headless mode by instructing the user to open the URL in a browser. * Fix line too long * Update changelog * Clarify changelog entry * Remove reduntant log about pasting the URL.
This commit is contained in:
parent
f7fb8757e9
commit
cc5e234a28
@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- Support to search multiple markets at once.
|
- Support to search multiple markets at once.
|
||||||
- Support to search all available Spotify markets.
|
- Support to search all available Spotify markets.
|
||||||
|
- Allow for OAuth 2.0 authorization by instructing the user to open the URL in a browser instead of opening the browser.
|
||||||
|
|
||||||
|
|
||||||
## [2.13.0] - 2020-06-25
|
## [2.13.0] - 2020-06-25
|
||||||
|
|
||||||
|
|||||||
@ -374,9 +374,17 @@ class SpotifyOAuth(SpotifyAuthBase):
|
|||||||
except webbrowser.Error:
|
except webbrowser.Error:
|
||||||
logger.error("Please navigate here: %s", auth_url)
|
logger.error("Please navigate here: %s", auth_url)
|
||||||
|
|
||||||
def _get_auth_response_interactive(self):
|
def _get_auth_response_interactive(self, open_browser=True):
|
||||||
self._open_auth_url()
|
if open_browser:
|
||||||
response = SpotifyOAuth._get_user_input("Enter the URL you were redirected to: ")
|
self._open_auth_url()
|
||||||
|
prompt = "Enter the URL you were redirected to: "
|
||||||
|
else:
|
||||||
|
url = self.get_authorize_url()
|
||||||
|
prompt = (
|
||||||
|
"Go to the following URL: {}\n"
|
||||||
|
"Enter the URL you were redirected to: ".format(url)
|
||||||
|
)
|
||||||
|
response = SpotifyOAuth._get_user_input(prompt)
|
||||||
state, code = SpotifyOAuth.parse_auth_response_url(response)
|
state, code = SpotifyOAuth.parse_auth_response_url(response)
|
||||||
if self.state is not None and self.state != state:
|
if self.state is not None and self.state != state:
|
||||||
raise SpotifyStateError(self.state, state)
|
raise SpotifyStateError(self.state, state)
|
||||||
@ -397,7 +405,7 @@ class SpotifyOAuth(SpotifyAuthBase):
|
|||||||
else:
|
else:
|
||||||
raise SpotifyOauthError("Server listening on localhost has not been accessed")
|
raise SpotifyOauthError("Server listening on localhost has not been accessed")
|
||||||
|
|
||||||
def get_auth_response(self):
|
def get_auth_response(self, open_browser=True):
|
||||||
logger.info('User authentication requires interaction with your '
|
logger.info('User authentication requires interaction with your '
|
||||||
'web browser. Once you enter your credentials and '
|
'web browser. Once you enter your credentials and '
|
||||||
'give authorization, you will be redirected to '
|
'give authorization, you will be redirected to '
|
||||||
@ -407,7 +415,11 @@ class SpotifyOAuth(SpotifyAuthBase):
|
|||||||
redirect_info = urlparse(self.redirect_uri)
|
redirect_info = urlparse(self.redirect_uri)
|
||||||
redirect_host, redirect_port = get_host_port(redirect_info.netloc)
|
redirect_host, redirect_port = get_host_port(redirect_info.netloc)
|
||||||
|
|
||||||
if redirect_host in ("127.0.0.1", "localhost") and redirect_info.scheme == "http":
|
if (
|
||||||
|
open_browser
|
||||||
|
and redirect_host in ("127.0.0.1", "localhost")
|
||||||
|
and redirect_info.scheme == "http"
|
||||||
|
):
|
||||||
# Only start a local http server if a port is specified
|
# Only start a local http server if a port is specified
|
||||||
if redirect_port:
|
if redirect_port:
|
||||||
return self._get_auth_response_local_server(redirect_port)
|
return self._get_auth_response_local_server(redirect_port)
|
||||||
@ -419,9 +431,7 @@ class SpotifyOAuth(SpotifyAuthBase):
|
|||||||
'the URL your browser is redirected to.',
|
'the URL your browser is redirected to.',
|
||||||
redirect_host, redirect_host)
|
redirect_host, redirect_host)
|
||||||
|
|
||||||
logger.info('Paste that url you were directed to in order to '
|
return self._get_auth_response_interactive(open_browser=open_browser)
|
||||||
'complete the authorization')
|
|
||||||
return self._get_auth_response_interactive()
|
|
||||||
|
|
||||||
def get_authorization_code(self, response=None):
|
def get_authorization_code(self, response=None):
|
||||||
if response:
|
if response:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user