From e9403f1585ac81d9868c1cedf23134b6a7171734 Mon Sep 17 00:00:00 2001 From: vmdominguez Date: Fri, 9 Jul 2021 09:57:43 -0500 Subject: [PATCH] Fix authorization flow failing on iOS when server response has no data (#161) --- .../Source/ByteowlsCapacitorOauth2.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ios/ByteowlsCapacitorOauth2/Source/ByteowlsCapacitorOauth2.swift b/ios/ByteowlsCapacitorOauth2/Source/ByteowlsCapacitorOauth2.swift index adb8f43f..dac9491f 100644 --- a/ios/ByteowlsCapacitorOauth2/Source/ByteowlsCapacitorOauth2.swift +++ b/ios/ByteowlsCapacitorOauth2/Source/ByteowlsCapacitorOauth2.swift @@ -355,14 +355,19 @@ public class OAuth2ClientPlugin: CAPPlugin { call.reject(self.ERR_GENERAL) } } - } else { + } else if let responseData = response?.data { do { - let jsonObj = try JSONSerialization.jsonObject(with: response!.data, options: []) as! JSObject + let jsonObj = try JSONSerialization.jsonObject(with: responseData, options: []) as! JSObject call.resolve(jsonObj) } catch { self.log("Invalid json in response \(error.localizedDescription)") call.reject(self.ERR_GENERAL) } + } else { + // `parameters` will be response parameters + var result = parameters + result.updateValue(credential.oauthToken, forKey: self.JSON_KEY_ACCESS_TOKEN) + call.resolve(parameters) } case .failure(let error): switch error {