kylebrowning / waterwheel.swift

The Waterwheel Swift SDK provides classes to natively connect iOS, macOS, tvOS, and watchOS applications to Drupal 7 and 8.
MIT License
411 stars 93 forks source link

signRequset in drupal-ios-sdk is not working properly #119

Closed vivekvpandya closed 8 years ago

vivekvpandya commented 9 years ago

Hello Kyle,

As per my understanding the variable signRequest in DIOSSession class allows developer to specify whether to pass credential details with request or not.

So following code will add Authorization header with request is signRequest is YES.

 if (self.signRequests) {

        [self.requestSerializer setAuthorizationHeaderFieldWithUsername:_basicAuthUsername password:_basicAuthPassword];
    }

but what if developer wants to disable sending credential temporarily for one request ? by setting signRequest to NO does not remove Authorization header. Or if user has changed the password from website and it has not provide new password in app. So following code fix it for me :

    if (self.signRequests) {

        [self.requestSerializer setAuthorizationHeaderFieldWithUsername:_basicAuthUsername password:_basicAuthPassword];
    }
    else{
        // If previously signRequest is set to YES then if temparoraly it has been set to NO then authorization header should be cleared
        [self.requestSerializer clearAuthorizationHeader];

    }

So kindly review this and give your valuable input to this issue.

Thanks !

kylebrowning commented 9 years ago

Hey @vivekvpandya Very interesting use case.

Can you show me how you are making your calls just so I can show you how to cancel the request for a specific request.

vivekvpandya commented 9 years ago

Actually , our app has manage user account screen from where they can change their account details (i.e PATCH on /entity/user ) but this screen is only available to logged in users. So I keep a valid credentials around the app till i did not get 401 for any authorized request. here if PATCH request fails I have simple if condition as shown below :

                        else if(statusCode == 401){
                            User *user = [User sharedInstance];
                            [user clearUserDetails];
                            DIOSSession *sharedSession = [DIOSSession sharedSession];
                            sharedSession.signRequests = NO;

                            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please verify login credentials first." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
                            [alert show];

                        }

So if provided credentials are wrong ( as it has been changed by user through the web site) the app is logging out the user and no request should be supplying credentials any more until login is done by user. I hope this scenario helps.

kylebrowning commented 8 years ago

Interesting. Okay. I think this issue is fixed in the 4.x branch because swift is way easier to manage.