Seller Central
Seller Forums

Amazon Seller Forums » Login With Amazon » Questions about Login With Amazon

Thread: Can't get the login with Amazon window to go away after clicking "sign-in"
This question is answered.


Permlink Replies: 5 - Pages: 1 - Last Post: 03 Mar, 2017 12:15 PM by: Yancheng G. (LWA)
Rob Moncur

Posts: 3
Registered: 17 Sep, 16 8:32 PM
Posted on: 10 Dec, 2016 6:00 PM  
Click to report abuse...   Click to reply to this thread Reply
I'm working on integrating login with Amazon into my iOS app. I've gotten the SDK installed and I've been using the documentation here to try and get it working: http://login.amazon.com/ios

I'm writing my app in swift instead of objective c, so I've had to do some translation of the code. Mine looks like this.

My code looks like this:

@IBAction func clickLoginWithAmazon(sender: UIButton) {

let myrequest = AMZNAuthorizeRequest()
myrequest.scopes.append(AMZNProfileScope.profile())
myrequest.interactiveStrategy = AMZNInteractiveStrategy.Auto

let sharedManager: AMZNAuthorizationManager = AMZNAuthorizationManager()

sharedManager.authorize(myrequest) { (result:AMZNAuthorizeResult?, userDidCancel: Bool, error:NSError?) in
if ((error) != nil) {
// Handle errors from the SDK or authorization server.
} else if (userDidCancel) {
// Handle errors caused when user cancels login.
} else {
// Authentication was successful.
let accessToken = result!.token
}
}

}

I can successfully call this method, which brings up the login with amazon screen in a window in the app. I can type in a username and password. After clicking the sign-in button nothing happens. The sign-in screen (in the safari web view) just stays there. In the console in Xcode there is a line that says “withApplication:withURL”. It won’t trigger the callback either. If I click “Cancel” or “Done” it will then call the callback and give me a “userDidCancel” error.

I don’t know how to overcome this. I don’t know why the sign-in window won’t close. I’m at a complete loss.

I’m seeing this same behavior on the iPhone simulator and on my actual device. I am using Xcode 8.2 beta using Swift 2.3 (? I think). The app I’m using was originally a sample app from AWS Mobile Hub.

Also, I’ve downloaded the CognitoSync demo app
https://github.com/awslabs/aws-sdk-ios-samples/tree/master/CognitoSync-Sample/Swift
and was able to get it working just fine. I did not see the same behavior there.

Any thoughts about why this is happening?

Is this a helpful question? Yes 1   No
5 Replies
Sort replies by:
Jeon Seo Yoon

Posts: 3
Registered: 21 Dec, 16 6:04 AM
Posted on: 22 Dec, 2016 2:55 AM   in response to: Rob Moncur in response to: Rob Moncur  
Click to report abuse...   Click to reply to this thread Reply
hello. I have read your email now. May i know what for the reason that you sent me this message? Are you from an Amazon services or? Please gently reply me about it, because I still have unsolved problem with me, I'm wondering whether this email is able to help my issue of problem or Its just a sort of advertising. Thank you.
Was this reply helpful? Yes 0   No 3
TEXTURE

Posts: 2
Registered: 23 Aug, 16 9:48 PM
Posted on: 01 Mar, 2017 2:46 PM   in response to: Rob Moncur in response to: Rob Moncur  
Click to report abuse...   Click to reply to this thread Reply
Have you received any feedback on this? I'm currently experiencing the same issue.
Was this reply helpful? Yes 0   No 0
TEXTURE

Posts: 2
Registered: 23 Aug, 16 9:48 PM
Posted on: 02 Mar, 2017 2:44 PM   in response to: Rob Moncur in response to: Rob Moncur  
Click to report abuse...   Click to reply to this thread Reply
To resolve this you need to call this method

AMZNAuthorizationManager handleOpenURL:url sourceApplication:sourceApplication;

in

  • (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

of your appdelegate
Was this reply helpful? Yes 0   No 0
Rob Moncur

Posts: 3
Registered: 17 Sep, 16 8:32 PM
Posted on: 02 Mar, 2017 4:19 PM   in response to: TEXTURE in response to: TEXTURE  
Click to report abuse...   Click to reply to this thread Reply
Cool, thanks for the update. I'm glad you figured this out. I ended up going through a lot of trouble to get this working, so it's exciting to see you figure it out.
Was this reply helpful? Yes 0   No 0
Yancheng G. (LWA)

Posts: 24
Registered: 17 Jun, 14 4:37 PM
Posted on: 03 Mar, 2017 12:15 PM   in response to: Rob Moncur in response to: Rob Moncur  
Click to report abuse...   Click to reply to this thread Reply
Hello,

In order for LoginWithAmazon SDK to handle the authorize response, you will need to implement application:openURL:options: in the class that handles UIApplicationDelegate protocol (By default, this will be the AppDelegate class). Within this method, call handleOpenURL:sourceApplication: defined in AMZNAuthorizationManager. This would enable LWA SDK to handle any server side response and dismiss the SafariViewController. Note that before iOS 9.0, this method was called in application:openURL:sourceApplication:annotation: in your AppDelegate class, however, since application:openURL:sourceApplication:annotation: has been deprecated, we would recommend to switch to use application:openURL:options: instead. Here is our sample code on how to implement your application:openURL:options: method and call handleOpenURL:sourceApplication:

-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL isValidRedirectLogInURL = [AMZNAuthorizationManager handleOpenURL:url sourceApplication:optionsUIApplicationOpenURLOptionsSourceApplicationKey];

if(!isValidRedirectLogInURL)
return NO;

// App may also want to handle url
return YES;
}

For Swift apps, you should implement application(_:open:options:) in AppDelegate class and call handleOpen(_ :sourceApplication:) method defined in AMZNAuthorizationManager class.

Thank you.
Was this reply helpful? Yes 0   No 0