uber / uber-ios-sdk

Uber iOS SDK (beta)
https://developer.uber.com/docs
MIT License
376 stars 125 forks source link

Authorization failure #80

Closed slysid closed 7 years ago

slysid commented 8 years ago

Hi,

I am trying to integrate UBER into my iOS app and I have installed the SDK using Cocoapods. My app is an Objective C native app and the SDK is in Swift. I have implemented necessary steps in making Swift UBER SDK to work with by Objective C app.

Now the issue I am facing is, I have a custom UIButton which when tapped calls a IBAction method as below (this is from official iOS SDK Documentation)

-(IBAction)uberTapped:(id)sender
{
    UBSDKLoginManager *loginManager = [[UBSDKLoginManager alloc] initWithLoginType:UBSDKLoginTypeAuthorizationCode];
    NSArray<UBSDKRidesScope *> *scopes = @[UBSDKRidesScope.Profile];

    [loginManager loginWithRequestedScopes:scopes presentingViewController:self completion:^(UBSDKAccessToken * _Nullable accessToken, NSError *error) {
        if (error) {
            NSLog(@"%@", error.localizedDescription);
            // Handle error
            return;
        }

  }];
}

When the button is tapped, an authentication view is presented. When I enter the credentials and press tap, there is a failure message

Error Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value.} The error is from KeychainWrapper.swift

func setObject(object: NSCoding, key: String) -> Bool {
    var keychainItemData = getKeychainItemData(key)

    let value = NSKeyedArchiver.archivedDataWithRootObject(object)
    keychainItemData[AttrAccessible] = kSecAttrAccessibleWhenUnlocked
........

I am not sure how to fix this issue. Is this an error in SDK?

jbrophy17 commented 8 years ago

Sorry to hear you're having trouble, this does seem like strange behavior. After you enter your credentials are you presented with the scope accept screen or does the error occur immediately? I am having trouble reproducing it on my end

slysid commented 8 years ago

Thank you for your response. Once I entered the credentials and clicked login, I am presented with the error in the console and the app is unresponsive. I am not presented with any scope acceptance screen.

screen shot 2016-08-16 at 00 35 30
jbrophy17 commented 8 years ago

Okay thanks for the info, a few more questions to help me dig in on this: Were you ever able to successfully log in or have you always been getting this error? Are you running your code on simulator or on a device? If on device, what type & iOS version? If on simulator, does it work if you try a different simulator? What version of the SDK are you using?

slysid commented 8 years ago

Hi,

Please see my response below Were you ever able to successfully log in or have you always been getting this error?

I am always getting the error and not able to login at all

Are you running your code on simulator or on a device?

I am running on actual device

If on device, what type & iOS version?

iPhone 6S, iOS 9.3.4(13G35)

What version of the SDK are you using?

UberRides (0.5.2):

  • ObjectMapper (~> 1.0)
jbrophy17 commented 8 years ago

Hi @slysid sorry for the delay here. While I am still unable to reproduce it, it appears that you are potentially attempting to save a nil accessToken. Within you login completion block, are you doing any custom logic for saving your token?

I also notice that you are using the UBSDKLoginTypeAuthorizationCode login type, is that intentional? Using this login type requires that you have set up your own back end to handle the authorization code grant flow.

When you use this type, the completion block from your login manager will return nil for both access token and error, expecting you to fetch the access token yourself from the server. So only checking for an error and then attempting to save the token yourself could cause the issue you're seeing.

Could you try using UBSDKLoginTypeImplicit with your code, just to see if you experience the same error?

jbrophy17 commented 7 years ago

Closing due to inactivity. Feel free to re-open if you are still seeing this issue.

I would also suggest heading over to Stack Overflow and using the uber-api tag for implementation help