alexa-samples / alexa-smarthome

Resources for Alexa Smart Home developers.
https://alexa.design/smarthome
Other
685 stars 336 forks source link

Unable to exchange bearer token for consistent cognito id anymore #50

Closed rlbartle closed 11 months ago

rlbartle commented 6 years ago

This had worked for the last 2 months and was used for a published skill. A couple of days ago I tried to discover devices and it didn't work anymore and it turns out the behaviour of something has changed. My skill uses the linked account identity to determine what devices the user can discover/control. This is done by storing the CognitoID of the linked account and the id of each device in a database. Here is the code that previously worked.

def lambda_handler(request, context):
    access_token = request["directive"]["payload"]["scope"]["token"]
    response = boto3.client("cognito-identity", "us-east-2").get_id(
            AccountId="xxxxxxxxxxxx",
            IdentityPoolId="us-east-2:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            Logins={
                "www.amazon.com": access_token
            }
        )

When I check the logs I see that the cognito id returned by each new discovery request results in a unique cognito id. Before it returned the cognito id of the linked user account.

EDIT:

Ok it turns out these are unsolicited discovery requests (about 60 a day) and each one has a unique user id. Using the token info REST api endpoint, the users are definitely not linked accounts. I don't know where they're coming from but it pollutes my cognito identity store with all these bogus identities. If only cognito had an option to retrieve and not generate identities.

rlbartle commented 6 years ago

My amazon account was changed to the amazon.com.au store, making my skills and devices from the original store hidden. When changing it back to amazon.com, the cognito id stuff works properly.

Having skills enabled in different stores seems to be part of the problem. I tried removing the skill from the amazon.com store, and switching back to the au one, but the discover wouldn't even log anything. It seems like the topic issue occurs when a discover is performed with the main amazon.com store but instead the au variant sends bogus stuff. Perhaps of note, the development skill in my account is always the US variant. Maybe that's part of the problem as it should be AU.

I'd say the reason why the au store version doesn't discover anything is because of all the errors here in the web console log

aszk commented 11 months ago

I believe that is most likely endpoint issue. If a user is AU, you need to use US West (Oregon) endpoint. https://developer.amazon.com/en-US/docs/alexa/smarthome/develop-smart-home-skills-in-multiple-languages.html#deploy If this doesn't solve the issue, please feel free to use https://alexa.design/contactus