question

vijay3 avatar image
vijay3 asked

Getting auth token from iOS app in Swift

Hi, Am trying to get an auth token from iOS app in Swift. The following is what I have done - registered a new device in developer portal and attached to a Security Profile - created a API key for iOS app - attached the Security profile to Login With Amazon in Developer portal - created a new iOS app in Swift and linked LoginWithAmazon.framework - added a new APIKey attribute to Info.plist - added ATS keys to Info.plist - login with amazon button code is as follows let deviceTypeID = "ABC123" let deviceSerialNumber = "123" let requestScopes = ["alexa:all"] var scopeData:String var options = [String:AnyObject]() scopeData = "{\"alexa:all\":{\"productID\":\"\(deviceTypeID)\",\"productInstanceAttributes\":{\"deviceSerialNumber\":\"\(deviceSerialNumber)\"}}}" options[kAIOptionScopeData] = scopeData AIMobileLib.authorizeUserForScopes(requestScopes, delegate: self, options: options) When I run the application and click the login button, I get the following message in console 2016-04-18 11:01:32.972 AskMe[8371:308634] LaunchServices: ERROR: There is no registered handler for URL scheme com.amazon.lwa.sso and the login amazon screen opens up. I enter the username/password and click submit nothing happens and it still shows the same login page. Regards, Vijay
alexa voice service
10 |5000

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

elstryan@Amazon avatar image
elstryan@Amazon answered
Hi Vijay, It looks like from your description of what you have already done in your project you're missing adding the URL schemes to the property list. The steps to do this are detailed under the heading "Add a URL Scheme to Your App Property List" of step #4 at this link: http://login.amazon.com/ios Thanks Ryan
10 |5000

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

vijay3 avatar image
vijay3 answered
Hi Ryan, Sorry I didnt include it in the original message but I have already configured URL types with URL identifier set to App's bundle id and URL schemes set to amzn- . Do I need to add anything to the app delegate function? Regards, Vijay
10 |5000

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

elstryan@Amazon avatar image
elstryan@Amazon answered
Hi Vijay, Regarding the "There is no registered handler for URL scheme com.amazon.lwa.sso" - this is safe to ignore. This will be logged out on any devices that don't have the amazon shopping installed. Generally the most likely reason that you would get stuck on the SignIn page is incorrect values configured in URLIdentifier/URLScheme but since you've already checked that I'll need some more information to debug this. 1) Where do you see the signIn page open up when you click the login button in your app? Is it in a Safari web view? 2) Can you provide the SignIn urls and any request url after hitting the submit button on the SignIn page (You can use safari browser developer mode on your desktop 3) If confirmed the issue is not being able to redirect from the browser back to the app, then check your URLIdentifier/URLScheme settings in .plist file. Also, check your project’s info.plist file property to make sure you are loading the correct .plist file. Thanks, Ryan V
10 |5000

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

vijay3 avatar image
vijay3 answered
Hi Ryan, Thanks for the pointers. Please see my feedback below 1. Signin page opens within the app. I see a Done button on the top left and also there is a Safari icon on the bottom right. If I click the Safari icon on the bottom right then it opens the sign in page in a safari window. 2. The signin page by default opens inside the app and when i click signin it stays in the same page. But if I click the Safari icon at the bottom right and then fill the fields and signin it pops up a msg saying 'Open in app'. Click yes and it shows the signin page that was previously opened in the app. 3. The project's plist property refers to Info.plist and the Info.plist contains URLIdentifier set to bundle id of the app and URLSchemes is set to amzn- . What is the value to be set in URLIdentifier/URLScheme? Regards, Vijay
10 |5000

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

elstryan@Amazon avatar image
elstryan@Amazon answered
Hi Vijay, In order to debug further I'll need the URLs that are in your browser when you login. To do this click the login button and then once you get the get the sign in page click the safari icon in the bottom right. Once the page opens in Safari cut and paste the URL from the browser and repost it here. Additionally can you please provide: 1) The security profile ID you are getting from the API keys from for your application? 2) The URL Scheme that you are putting into the .plist file?
10 |5000

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

vijay3 avatar image
vijay3 answered
Hi Ryan, There was an iOS documentation somwhere in the Amazon which pointed to registering in sellercentral and creating an app with security profile. I did that first and then I created a security profile in developer.amazon.com. In my app, I have set the API Key to the Security profile created in developer site. But the bundle id use in both (sellercentral app and developer app are same). Am not sure if this is causing the issue. I have raised a ticket to delete the sellercentral app and even cancel the sellercentral account. Do you think this could be causing a problem? 1. The security profile name gets displayed correctly on the login page as per the API Key. 2. The URL scheme is 'amzn- '. The is the one that I have configured in the Security Profile. I will send you the safari URLs once in a while. Regards, Vijay
10 |5000

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

elstryan@Amazon avatar image
elstryan@Amazon answered
Hi Vijay, One more thing I'd like to check: Have you implemented application:openURL:sourceApplication:annotation: in the class in your project that handles the UIApplicationDelegate protocol? There are more details on Step #6 of http://login.amazon.com/ios and the sub-step #10. If you don't follow this step the app won't be able to response to the redirect from safari. I'll wait to get the URLs so I can look into this more. One more clarifying point: I'm looking for the security profile id that is displayed in the developer.amazon.com page. You can find it via Alexa->Alexa Voice Service-> Edit the product you are working on -> Click security profile then you should see a row in the table with "Security Profile Id". One more thing that might help: we provide a sample iOS app with steps for using it to authenticate here: https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/java-client-sample. Note it's objective c rather than swift and its designed to authenticate a separate physical device rather than the mobile device itself. However some of the code there might serve as a useful example - particularly the LoginController.
10 |5000

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

vijay3 avatar image
vijay3 answered
Hi Ryan, Implementing application:openURL:sourceApplication resolved the issue. Now the login screen returns back to the app and then calling getAccessToken returns the auth code. Thanks for the support. Regards, Vijay
10 |5000

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