alexa / alexa-skills-kit-sdk-for-python

The Alexa Skills Kit SDK for Python helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
https://developer.amazon.com/en-US/docs/alexa/alexa-skills-kit-sdk-for-python/overview.html
Apache License 2.0
812 stars 206 forks source link

Receiving unauthorized_client error trying to list all skills #187

Closed reddit-at-work closed 3 years ago

reddit-at-work commented 3 years ago

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[x ] Other... Please describe: trouble with authentication, receiving unauthorized_client error

I've setup everything as outlined in the guide: a user profile, used ask-cli to generate tokens and replaced the refresh_token with the one I receive

Someone did raise the issue before #174 , but the issue was closed with no resolution

from ask_smapi_sdk import StandardSmapiClientBuilder
smapi_client_builder = StandardSmapiClientBuilder(client_id=client_id, client_secret=client_secret, refresh_token=response['refresh_token'])
smapi_client = smapi_client_builder.client()
try:
    result = smapi_client.list_skills_for_vendor_v1(vendor_id=vendor_id, full_response=True)
    print("==========================================")
    print(result.headers)
    print(result.body)
    print("==========================================")
except Exception as e:
    print(e.body if hasattr(e, 'body') else e)

Expected Behavior

List of skills

Current Behavior

{'error_description': 'Not authorized for requested operation', 'error_type': 'unauthorized_client'}

Your Environment

Python version info

Shreyas-vgr commented 3 years ago

Hi @reddit-at-work, thanks for raising the issue. It seems to be an issue with LWA(Login With Amazon) service where SkillManagementServiceClient is unable to retrieve the access_token from the refresh_token being passed onto the builder.

Let me contact the respective service team owners and fix the issue, will update the ticket once I get a resolution. Sorry for the inconvenience caused.

Shreyas-vgr commented 3 years ago

Hi @reddit-at-work, Can you try regenerating tokens using ASK-CLI v2 with arguments shown below ask util generate-lwa-tokens --clientId <YOUR_CLIENT_ID> --client-confirmation <YOUR_CLIENT_SECRET> and then provide the output refresh_token generated to the StandardSmapiClientBuilder ?

I believe executing ask util generate-lwa-tokens without any argument picks up the CLI's client_id and client_secret by default which might be causing the above error you've raised.

reddit-at-work commented 3 years ago

Hi @Shreyas-vgr, that solved the issue. Thank you very much! Although I'd to use client-id, client-confirmation in place of clientId and client-secret.