question

Calabrone avatar image
Calabrone asked

Problem with account linking: INVALID_ACCESS_TOKEN_EXCEPTION

I'm trying to develop a Smart Home Skill, but i can't go on with the discovery procedure.

My skill id is: amzn1.ask.skill.b9236e0b-6daf-455c-9fac-270106175329

The skill correctly login with account linking and is anabled, but when alexa launches the discovery procedure it fails with an "INVALID_ACCESS_TOKEN_EXCEPTION".

I use the same token i retrieve from the discovery directive!

This is what i got from Alexa

{
    "directive": {
        "header": {
            "namespace": "Alexa.Discovery",
            "name": "Discover",
            "payloadVersion": "3",
            "messageId": "e525927f-2ace-415b-9776-0158817a0229"
        },
        "payload": {
            "scope": {
                "type": "BearerToken",
                "token": "Atza|IwEBIC6G9nx5BPmczjAauLUjNlrZkn0rNt0ZoIuihvHPCoiqM8bWt7T3l8wKbjMz2brLiSQBHWgmkjxOL8qF7xUUDCDdRxifZhvzsxmevBZ_z6tE-Ns8wp-ewRKWkIqhEvJJEyIIm87uGCLhP8YlqSGDgNNW9B0Pd_MsYMdO379tiJWtkpaO3YzLS44X7WNwHrSwFEHL5M8dypIssJwTjxQR-NayERdEX83Wk5D8APjziktzUUAH__vctVpIRAqme5nmVWFlq7IWpfOjXhIusSZofn6YNGwBmazUcOr1BT7xTBeF7UPsylMVMfjYsUs7rVOiOKeb93iiysmjQjoanxUqtirty8PPz0RRTVXWrkUlGNffcwpOp2NeNEk2AX3MCBu5V7s2vmn4kni708ZZrEdzULPOMRRakQ-ZqMInF_bzla2ZH4lp3ztVwNINgRicRmJR-TI-5HG-RxJxV4XEpmLpxrT2FjpNjK3hCv1_EjcPHbN1vPyZ4P0WUv16lcAh0dJnT-CefBkCrxgo22pOEGRG9eZd"
            }
        }
    }
}

Then i reply with this sample code:

header

{
    "Authorization": "Bearer Atza|IwEBIC6G9nx5BPmczjAauLUjNlrZkn0rNt0ZoIuihvHPCoiqM8bWt7T3l8wKbjMz2brLiSQBHWgmkjxOL8qF7xUUDCDdRxifZhvzsxmevBZ_z6tE-Ns8wp-ewRKWkIqhEvJJEyIIm87uGCLhP8YlqSGDgNNW9B0Pd_MsYMdO379tiJWtkpaO3YzLS44X7WNwHrSwFEHL5M8dypIssJwTjxQR-NayERdEX83Wk5D8APjziktzUUAH__vctVpIRAqme5nmVWFlq7IWpfOjXhIusSZofn6YNGwBmazUcOr1BT7xTBeF7UPsylMVMfjYsUs7rVOiOKeb93iiysmjQjoanxUqtirty8PPz0RRTVXWrkUlGNffcwpOp2NeNEk2AX3MCBu5V7s2vmn4kni708ZZrEdzULPOMRRakQ-ZqMInF_bzla2ZH4lp3ztVwNINgRicRmJR-TI-5HG-RxJxV4XEpmLpxrT2FjpNjK3hCv1_EjcPHbN1vPyZ4P0WUv16lcAh0dJnT-CefBkCrxgo22pOEGRG9eZd",
    "Content-Type": "application/json;charset=UTF-8"
}

payload

{
    "event": {
        "header": {
            "namespace": "Alexa.Discovery",
            "name": "Discover.Response",
            "payloadVersion": "3",
            "messageId": "b4c48994-a2b1-49c1-a2d7-89eda7e99ae3"
        },
        "payload": {
            "endpoints": [
                {
                    "endpointId": "appliance-001",
                    "friendlyName": "Living Room Light",
                    "description": "Smart Light by Sample Manufacturer",
                    "manufacturerName": "Sample Manufacturer",
                    "displayCategories": [
                        "LIGHT"
                    ]
                }
            ],
            "scope": {
                "type": "BearerToken",
                "token": "Atza|IwEBIC6G9nx5BPmczjAauLUjNlrZkn0rNt0ZoIuihvHPCoiqM8bWt7T3l8wKbjMz2brLiSQBHWgmkjxOL8qF7xUUDCDdRxifZhvzsxmevBZ_z6tE-Ns8wp-ewRKWkIqhEvJJEyIIm87uGCLhP8YlqSGDgNNW9B0Pd_MsYMdO379tiJWtkpaO3YzLS44X7WNwHrSwFEHL5M8dypIssJwTjxQR-NayERdEX83Wk5D8APjziktzUUAH__vctVpIRAqme5nmVWFlq7IWpfOjXhIusSZofn6YNGwBmazUcOr1BT7xTBeF7UPsylMVMfjYsUs7rVOiOKeb93iiysmjQjoanxUqtirty8PPz0RRTVXWrkUlGNffcwpOp2NeNEk2AX3MCBu5V7s2vmn4kni708ZZrEdzULPOMRRakQ-ZqMInF_bzla2ZH4lp3ztVwNINgRicRmJR-TI-5HG-RxJxV4XEpmLpxrT2FjpNjK3hCv1_EjcPHbN1vPyZ4P0WUv16lcAh0dJnT-CefBkCrxgo22pOEGRG9eZd"
            }
        }
    }
}

I put the access token both in the header and in the scope.

I've done many tests (token only in header and viceversa) but with the same result: this is what i get

{
    "header": {
        "namespace": "System",
        "name": "Exception",
        "messageId": "a4658eb3-6e00-4b78-826d-9e0ec9ddeb45"
    },
    "payload": {
        "code": "INVALID_ACCESS_TOKEN_EXCEPTION",
        "description": "Access token is not valid."
    }
}

There's a thing i did not clearly undertand: when i make account linking all seems to going on in the rigth way. The account linking ends with this page

and the skill is anabled.

But my lambda doesn't receive any trigger: is it right?

My lambda is triggered only when alexa send the discovery directive with the access token.

Hope you can help me, i'm very frustrated.

alexa smart homeaccount linkingdevice discovery
cattura.png (37.7 KiB)
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

roy-1 avatar image
roy-1 answered

Hi Calabrone,

Thanks for posting. Please see the following Discover.Response example from our tech docs:

https://developer.amazon.com/docs/device-apis/alexa-discovery.html#response

Please note that there is no scope in the body, nor is there a token event.header. We've got a sample smart switch skill linked near the top of our Smart Home GitHub which covers returning this response, that I hope you find helpful:

https://github.com/alexa/alexa-smarthome

Currently, device discovery is run either when a customer manually requests it, or periodically throughout the day. I hope this helps. Please let us know if you are still running into any issues.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.