Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem understanding login requirements #2

Closed
Barry4679 opened this issue Mar 14, 2019 · 2 comments
Closed

problem understanding login requirements #2

Barry4679 opened this issue Mar 14, 2019 · 2 comments

Comments

@Barry4679
Copy link

Hi, thanks for your project.

Some time ago I wrote a replacement scrobbler for Sonos written using Python 2, and accessing Sonos units via subscribing to their UPnP events.
I am looking at redeveloping this app using Python 3, and the official Sonos api.

I am interested in your project as it allows me to test concepts and the Sonos api, as well as being for ongoing use with my Sonos equipment.

I have installed sonos_cli, but am failing somewhere trying to match Sonos documentation and your documentation.

I supply info to sonos_cli to your set_config function as:

Then run your login function;

  • the browser window opens, and I supply credentials to Sonos
  • they display the :Allow xxxx to control your Sonos system" panel
  • I press their "OKAY" button
  • I see the page saying "You have logged into Sonos!"
  • your program kicks back into action, but I get oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client) ... and seem have been returned 401 from your call to Sonos

copy of debug log attached bellow

Am I correctly understanding what data is required by SONOS_CLIENT_ID and SONOS_CLIENT_SECRET?

I don't think that I have any other Sonos "ID", other than my Household ID, but doubt that it would be attached the "secret" for the Sonos Integration.

Also what should have I done for "Redirect URIs" and "Event Callback URL" in my Credentials tab at https://integration.sonos.com/integrations ?

For Redirect URIs I added http://localhost:5000 after reading your settings.py module

One other thing that I have noticed is I downloaded your app as sonos-cli-0.3.1.tar.gz

  • I didn't install via "Homebrew" or pip ... I am on Windows, and have Python 2.
  • I didn't know how to make Python 2 & 3 co-exist together properly, and didn't want to make to many changes while I am still just evaluating the official api for my task

So I manually installed using the above file that I downloaded ... It seemed to be missing the templates directory, and the two html files, from within sonos-cli 0.3.1\sonos\commands.

my debug log; I have redacted my client ID and secret

ready to start
click imported
sonos.commands imported
Please enter Sonos application ID:
Successfully configured Sonos CLI.
DEBUG:requests_oauthlib.oauth2_session:Generated new state cGCWLh3OSDIysqk69reZSAGHK79CcU.
DEBUG:requests_oauthlib.oauth2_session:Encoding client_id "xxxxx" with client_secret as Basic auth credentials.
DEBUG:requests_oauthlib.oauth2_session:Requesting url https://api.sonos.com/login/v3/oauth/access using method POST.
DEBUG:requests_oauthlib.oauth2_session:Supplying headers {'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'} and data {'grant_type': 'authorization_code', 'code': 'a640d904-9acc-46e7-b3a7-b7953a50ecd1', 'redirect_uri': 'http://localhost:5000', 'username': 'xxxxx', 'password': 'yyyyy'}
DEBUG:requests_oauthlib.oauth2_session:Passing through key word arguments {'json': None, 'timeout': None, 'auth': <requests.auth.HTTPBasicAuth object at 0x000002053C781668>, 'verify': True, 'proxies': None}.
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.sonos.com:443
DEBUG:urllib3.connectionpool:https://api.sonos.com:443 "POST /login/v3/oauth/access HTTP/1.1" 401 26
DEBUG:requests_oauthlib.oauth2_session:Prepared fetch token request body grant_type=authorization_code&code=a640d904-9acc-46e7-b3a7-b7953a50ecd1&redirect_uri=http%3A%2F%2Flocalhost%3A5000&username=xxxxx&password=yyyyy
DEBUG:requests_oauthlib.oauth2_session:Request to fetch token completed with status 401.
DEBUG:requests_oauthlib.oauth2_session:Request headers were {'User-Agent': 'python-requests/2.21.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json', 'Connection': 'keep-alive', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Content-Length': '206', 'Authorization': 'Basic MDg0YWU5ODktNzMyOS00NmE4LWJlMTMtMjRkZDNlZjM5MjJiOg=='}
DEBUG:requests_oauthlib.oauth2_session:Request body was grant_type=authorization_code&code=a640d904-9acc-46e7-b3a7-b7953a50ecd1&redirect_uri=http%3A%2F%2Flocalhost%3A5000&username=xxxxx&password=yyyyy
DEBUG:requests_oauthlib.oauth2_session:Response headers were {'Content-Type': 'application/json;charset=UTF-8', 'Strict-Transport-Security': 'max-age=31536000 ; includeSubDomains', 'X-Application-Context': 'login-service:prod', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Content-Length': '26', 'Expires': 'Thu, 14 Mar 2019 04:48:07 GMT', 'Cache-Control': 'max-age=0, no-cache, no-store', 'Pragma': 'no-cache', 'Date': 'Thu, 14 Mar 2019 04:48:07 GMT', 'Connection': 'close', 'Set-Cookie': 'JSESSIONID=954C4663CEAE7E6DA30B15C149E475D0; Path=/login/v3; Secure; HttpOnly, AWSELB=69BFEFC914A689BF6DC8E4652748D7B501ED60290D7EA60FC919515B6A74C4FF1FE8CC8DE4ABBF19CF0BCF4D50224AD32883861ABF2DB40F64EDDC685ADCEABCFAE6CDCBCD;PATH=/;MAX-AGE=1800'} and content {"error":"invalid_client"}.
DEBUG:requests_oauthlib.oauth2_session:Invoking 0 token response hooks.
xxxxx
yyyyy
Traceback (most recent call last):
File "cli.py", line 38, in
login()
File "D:\My Documents\Python\sonos-cli 0.3.1\sonos\commands\login.py", line 66, in login
data = _get_access_token(code)
File "D:\My Documents\Python\sonos-cli 0.3.1\sonos\commands\login.py", line 20, in _get_access_token
return auth.get_access_token(code)
File "D:\My Documents\Python\sonos-cli 0.3.1\sonos\api\auth.py", line 16, in get_access_token
return client.fetch_token(ACCESS_TOKEN_URL, code=code, username=SONOS_CLIENT_ID, password=SONOS_CLIENT_SECRET)
File "c:\Program Files\Python37\lib\site-packages\requests_oauthlib\oauth2_session.py", line 307, in fetch_token
self._client.parse_request_body_response(r.text, scope=self.scope)
File "c:\Program Files\Python37\lib\site-packages\oauthlib\oauth2\rfc6749\clients\base.py", line 415, in parse_request_body_response
self.token = parse_token_response(body, scope=scope)
File "c:\Program Files\Python37\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 425, in parse_token_response
validate_token_parameters(params)
File "c:\Program Files\Python37\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 432, in validate_token_parameters
raise_from_error(params.get('error'), params)
File "c:\Program Files\Python37\lib\site-packages\oauthlib\oauth2\rfc6749\errors.py", line 405, in raise_from_error
raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client)
Process terminated with an exit code of 1

@rudyvan
Copy link

rudyvan commented Apr 9, 2019

My findings are as follows:

  1. when installing with pip, the directory templates in the directory commands is missing. work around is to create the template directory yourself and manually add ok.html and fail.html in the sonos directory in your python distr. This is a bug that should be corrected.

  2. you need to make sure that the redirect directory in your credentials in your sonos profile is http://localhost:5000 or during login sonos fails to return a credential. This is a documentation ommission that would be helpfull when added.

  3. you need to use your Client Credential Key, not the Key Name in sonos config

  4. then the sonos api returns a credential code (i can see that in the webbrowser) but then the sonos login program crashes:

Traceback (most recent call last):
  File "/usr/local/bin/sonos", line 10, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/sonos/decorators.py", line 70, in wrapper_config_required
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/sonos/commands/login.py", line 66, in login
    data = _get_access_token(code)
  File "/usr/local/lib/python3.6/dist-packages/sonos/commands/login.py", line 20, in _get_access_token
    return auth.get_access_token(code)
  File "/usr/local/lib/python3.6/dist-packages/sonos/api/auth.py", line 16, in get_access_token
    return client.fetch_token(ACCESS_TOKEN_URL, code=code, username=SONOS_CLIENT_ID, password=SONOS_CLIENT_SECRET)
  File "/usr/local/lib/python3.6/dist-packages/requests_oauthlib/oauth2_session.py", line 307, in fetch_token
    self._client.parse_request_body_response(r.text, scope=self.scope)
  File "/usr/local/lib/python3.6/dist-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 415, in parse_request_body_response
    self.token = parse_token_response(body, scope=scope)
  File "/usr/local/lib/python3.6/dist-packages/oauthlib/oauth2/rfc6749/parameters.py", line 425, in parse_token_response
    validate_token_parameters(params)
  File "/usr/local/lib/python3.6/dist-packages/oauthlib/oauth2/rfc6749/parameters.py", line 432, in validate_token_parameters
    raise_from_error(params.get('error'), params)
  File "/usr/local/lib/python3.6/dist-packages/oauthlib/oauth2/rfc6749/errors.py", line 405, in raise_from_error
    raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client)

now i am stuck, any help from someone?

@bwilczynski
Copy link
Owner

Invalid client issue is fixed, version 0.3.4 on PyPI also includes templates folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants