@@ -97,8 +97,9 @@ - (void) authorize:(NSDictionary *) parameters complete:(void (^) (Authenticatio
9797 NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod: @" POST" URLString: url parameters: authorizeParameters error: nil ];
9898 [request setValue: [NSString stringWithFormat: @" Bearer %@ " , token] forHTTPHeaderField: @" Authorization" ];
9999 NSURLSessionDataTask *task = [manager dataTaskWithRequest: request uploadProgress: nil downloadProgress: nil completionHandler: ^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
100+ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
101+
100102 if (error) {
101- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
102103
103104 // if the error was a network error try to login with the local auth module
104105 if ([error.domain isEqualToString: NSURLErrorDomain ]&& (error.code == NSURLErrorCannotConnectToHost|| error.code == NSURLErrorNotConnectedToInternet)) {
@@ -125,23 +126,27 @@ - (void) authorize:(NSDictionary *) parameters complete:(void (^) (Authenticatio
125126 return complete (AUTHENTICATION_ERROR, error.localizedDescription );
126127 }
127128 self.loginParameters = parameters;
128- self.response = responseObject;
129+
130+ NSMutableDictionary *responseDictionary = [[NSMutableDictionary alloc ] initWithDictionary: responseObject];
131+ responseDictionary[@" headers" ] = [httpResponse allHeaderFields ];
132+
133+ self.response = responseDictionary;
129134
130135 complete (AUTHENTICATION_SUCCESS, nil );
131136 }];
132137
133138 [manager addTask: task];
134139}
135140
136- - (void ) finishLogin : (void (^) (AuthenticationStatus authenticationStatus, NSString *errorString)) complete {
141+ - (void ) finishLogin : (void (^) (AuthenticationStatus authenticationStatus, NSString *errorString, NSString *errorDetail )) complete {
137142 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults ];
138143 NSDictionary *api = [self .response objectForKey: @" api" ];
139144
140145 if (self.response == nil ) {
141- complete (AUTHENTICATION_ERROR, @" Invalid server response" );
146+ complete (AUTHENTICATION_ERROR, @" Invalid server response" , nil );
142147 return ;
143148 } else if (self.loginParameters == nil ) {
144- complete (AUTHENTICATION_ERROR, @" Server login error" );
149+ complete (AUTHENTICATION_ERROR, @" Server login error" , nil );
145150 return ;
146151 }
147152
@@ -165,7 +170,8 @@ - (void) finishLogin:(void (^) (AuthenticationStatus authenticationStatus, NSStr
165170 if (tokenExpirationDate == nil ) {
166171 failureMessage = [NSString stringWithFormat: @" %@ Invalid Token Expiration Date<br>" , failureMessage];
167172 }
168- complete (AUTHENTICATION_ERROR, failureMessage);
173+
174+ complete (AUTHENTICATION_ERROR, failureMessage, [NSString stringWithFormat: @" Response Details %@ " , self .response]);
169175 return ;
170176 }
171177
@@ -215,7 +221,7 @@ - (void) finishLogin:(void (^) (AuthenticationStatus authenticationStatus, NSStr
215221 [StoredPassword persistPasswordToKeyChain: password];
216222 [StoredPassword persistTokenToKeyChain: token];
217223
218- complete (AUTHENTICATION_SUCCESS, nil );
224+ complete (AUTHENTICATION_SUCCESS, nil , nil );
219225 }];
220226}
221227
0 commit comments