question

newuser-95921952-c92f-4286-8e41-b885a4a6d68c avatar image

Request Error about iOS Companion AVS APP LWA Flow


I am developing an iOS companion app using this documentation: https://developer.amazon.com/en-US/docs/alexa/alexa-voice-service/authorize-companion-app.html.

I am currently trying to get the authorization code from LWA so that I can send it to my device. So far I have been stuck on this error. I have read the answers here: https://forums.developer.amazon.com/questions/27874/avs-after-i-select-ok-it-takes-me-a-screen-where-i.html and here: https://forums.developer.amazon.com/questions/54479/authorizing-android-alexa-app-is-impossible.html, as well as the answer here: https://forums.developer.amazon.com/questions/186459/login-with-amazon-an-error-occurred-when-we-tried-1.html.

So far I have not been able to solve for this error. I think that it must have something to do with my scope data, but I can't figure out what is wrong with it. Here is my code:

@IBAction func signInWithAmazonButtonTapped(_ sender: Any) {
        
        let productId = self.productID
        let productDsn = self.avsDsn
        let codeChallenge = self.avsCodeChallenge
        
        let scopeData: [String: Any] = ["productID": productId, "productInstanceAttributes": ["deviceSerialNumber": productDsn] ]
        
        let alexaAllScope = AMZNScopeFactory.scope(withName: "alexa:all", data: scopeData)
        let alexaSplashScope = AMZNScopeFactory.scope(withName: "alexa:voice_service:pre_auth")
        
        let request = AMZNAuthorizeRequest()
        request.scopes = [alexaSplashScope, alexaAllScope]
        request.codeChallenge = codeChallenge
        request.codeChallengeMethod = "S256"
        request.grantType = AMZNAuthorizationGrantType.code
        
        let handler: AMZNAuthorizationRequestHandler = { result, userDidCancel, error in
            
            if userDidCancel {
                fatalError("User did cancel")
                
            } else if let error = error {
                //TODO: Receive error 3 when user cancels login. Need to handle.
                NSLog("Received error authenticating with Alexa: \(error)")
                return
                
            } else {
                guard let result = result else {
                    fatalError("Could not get result authenticating with Alexa")
                }
                
                self.authCode = result.authorizationCode
                self.clientId = result.clientId
                self.redirectUri = result.redirectUri
                self.userSuccessfullySignedIn()
            }
        }
        authorize(request: request, withHandler: handler)
    }
}

Thank you for taking time to look over this question. Any help is appreciated.

login with amazonioscompanion app
10 |5000 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.

1 Answer

sungyoo avatar image
sungyoo answered

I think below GitHub issue thread might help! That error usually comes from mismatching credentials!

https://github.com/alexa/avs-device-sdk/issues/790

1 comment
10 |5000 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.