question

newuser-b6a8af64-7047-4eba-be85-e206c8c2286e avatar image
newuser-b6a8af64-7047-4eba-be85-e206c8c2286e asked ·

Cannot use LWA on ios with "alexa:all" scope

Hi. I'm trying to login with LWA from iOS(using swift 3). I've integrated everything as described here. But unfortunately after I press "I Agree" simulator-screen-shot-sep-8-2017-43957-pm.png I'm getting redirected on this error screen simulator-screen-shot-sep-8-2017-44000-pm.png.

Previously I've registered my app into avs console to get productID and APIKey for desired bundle ID.

My aim is to get direct access to AVS from the native iOS app. Any help would be really appreciated!

I use next code to get authorization token:

    private func alexa_createRequest()->AMZNAuthorizeRequest {

        let time:Date = Date.init()

        dateformatter .dateFormat = "ddMMyyyy-hh-mm-ss-a"

        let currentDateString = dateformatter .string(from: time)

        

        let uniqueDeviceSerialNumber = "serialNumUniqe".appending(currentDateString)

        

        let scopeData_alexa:[AnyHashable:Any] = [ kAIOptionScopeData :

            "{\"alexa:all\":{\"productID\":\"\(self.productID)\",\"productInstanceAttributes\": {\"deviceSerialNumber\":\"\(uniqueDeviceSerialNumber)\"}}}"]

        

        let scopeForAlexa = AMZNScopeFactory.scope(withName: "alexa:all", data: scopeData_alexa)

        let scopes_alexa = [scopeForAlexa]

        

        let alexaRequest:AMZNAuthorizeRequest = AMZNAuthorizeRequest()

        alexaRequest.scopes = scopes_alexa

        alexaRequest.grantType = .token

        

        return alexaRequest

    }

    

    func alexa_checkUserPermission() {

        let alexaRequest:AMZNAuthorizeRequest = self.alexa_createRequest()

        alexaRequest.interactiveStrategy = AMZNInteractiveStrategy.never

        

        let handler:AMZNAuthorizationRequestHandler = { [weak self] result, userDidCancel, error in

            if result != nil

            {

                self?._token = result!.token

                self?.delegate?.amazonAuthorizationExistingAccess(true, accessToken: result!.token, error: nil)

                

                self?._authorizationCode = result!.authorizationCode

                self?._clientId = result!.clientId

                self?._redirectUri = result!.redirectUri

            }

            else

            {

                let errorMessage:String = "the user is not authorized"

                self?.delegate?.amazonAuthorizationExistingAccess(false, accessToken: nil, error: errorMessage)

            }

        }


        self.authorize(request: alexaRequest, withHandler: handler)

    }
alexa voice servicelogin with amazonios
10 |2000 characters needed characters left characters exceeded

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

Jie@Amazon avatar image
Jie@Amazon answered ·

Hi @NewUser-b6a8af64-7047-4eba-be85-e206c8c2286e

Could you please get a new APIKey to reproduce this issue? If you use the wrong APIKey you will get this error.

Thanks.

1 comment
10 |2000 characters needed characters left characters exceeded

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

Hi. Do you mean APIKey generated for policy which I add to info.plist? I've tried wrong one on purpose and got error before login attempt which pointed me to problem with APIKey. Anyway, I could try to make a new policy and get another APIKey

0 Likes 0 ·
newuser-b6a8af64-7047-4eba-be85-e206c8c2286e avatar image
newuser-b6a8af64-7047-4eba-be85-e206c8c2286e answered ·

Still no luck :( Anyone succeed on login for AVS from iOS app?

1 comment
10 |2000 characters needed characters left characters exceeded

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

Hi, sorry to hear you're still blocked on this. Our documentation doesn't show Swift so it can be a little tricky to follow for your use-case.

One of the most common errors that causes the "We're sorry" page you're seeing is that there's some misformatting in your LWA Scope Data (i.e. your "scopeData_alexa" variable). If that JSON isn't perfect the login request will succeed but you'll see the "We're sorry" error.

You could try double checking that your JSON format is 100% correct (for instance, it looks like there's an extra space after "productInstanceAttributes\":). You should also double check that your "self.productID" variable matches your product ID on the Developer Portal: https://developer.amazon.com/avs/home.html#/avs/home

0 Likes 0 ·
tmomchev avatar image
tmomchev answered ·

I was able to Login With Amazon using this sample and following the README.md directions for what needs to be changed https://github.com/grimlockrocks/alexa-swift3-sample-app

10 |2000 characters needed characters left characters exceeded

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

newuser-caf9dd22-f95a-4c02-8a50-e067a62e88e1 avatar image
newuser-caf9dd22-f95a-4c02-8a50-e067a62e88e1 answered ·

I succeeded with below code.

let scopedData_alexa:[AnyHashable:Any] = [
                    "productID" : productID,
                    "productInstanceAttributes": [ "deviceSerialNumber" : deviceSerialNumber ]]


let scope_alexa = AMZNScopeFactory.scope(withName: "alexa:all", data:scopedData_alexa )

10 |2000 characters needed characters left characters exceeded

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