Skip to content

Commit 1060554

Browse files
authored
Merge pull request #53 from auth0/bugfix-remove-cache
Disable NSURLSession cache
2 parents 5b0fc6d + d65c1b1 commit 1060554

File tree

4 files changed

+17
-35
lines changed

4 files changed

+17
-35
lines changed

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

Guardian.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@
192192
5F20380E1D5E421F0005D2E2 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
193193
5F20380F1D5E421F0005D2E2 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
194194
5F2038111D5E42AD0005D2E2 /* .gitignore */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
195-
5F2038141D5E43CD0005D2E2 /* .travis.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .travis.yml; sourceTree = "<group>"; };
196-
5F2038161D5E43DD0005D2E2 /* .env */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = .env; path = script/.env; sourceTree = "<group>"; };
197195
5F2038181D5E46210005D2E2 /* Gemfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Gemfile; sourceTree = "<group>"; };
198196
/* End PBXFileReference section */
199197

@@ -406,8 +404,6 @@
406404
isa = PBXGroup;
407405
children = (
408406
5F2038181D5E46210005D2E2 /* Gemfile */,
409-
5F2038161D5E43DD0005D2E2 /* .env */,
410-
5F2038141D5E43CD0005D2E2 /* .travis.yml */,
411407
5F2038111D5E42AD0005D2E2 /* .gitignore */,
412408
5F20380C1D5E421F0005D2E2 /* Cartfile.resolved */,
413409
5F20380D1D5E421F0005D2E2 /* Cartfile.private */,

Guardian/Guardian.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222

2323
import Foundation
2424

25+
let nonCachedSession: URLSession = {
26+
let config = URLSessionConfiguration.default
27+
config.requestCachePolicy = .reloadIgnoringLocalCacheData
28+
config.urlCache = nil
29+
30+
return URLSession.init(configuration: config)
31+
}()
32+
2533
/**
2634
Creates a low level API client for Guardian MFA server
2735

@@ -36,7 +44,7 @@ import Foundation
3644

3745
- seealso: Guardian.API
3846
*/
39-
public func api(forDomain domain: String, session: URLSession = .shared) -> API {
47+
public func api(forDomain domain: String, session: URLSession = nonCachedSession) -> API {
4048
return api(url: url(from: domain)!, session: session)
4149
}
4250

@@ -54,7 +62,7 @@ public func api(forDomain domain: String, session: URLSession = .shared) -> API
5462

5563
- seealso: Guardian.API
5664
*/
57-
public func api(url: URL, session: URLSession = .shared) -> API {
65+
public func api(url: URL, session: URLSession = nonCachedSession) -> API {
5866
return APIClient(baseUrl: url, session: session)
5967
}
6068

@@ -76,7 +84,7 @@ public func api(url: URL, session: URLSession = .shared) -> API {
7684

7785
- seealso: Guardian.Authentication
7886
*/
79-
public func authentication(forDomain domain: String, andEnrollment enrollment: Enrollment, session: URLSession = .shared) -> Authentication {
87+
public func authentication(forDomain domain: String, andEnrollment enrollment: Enrollment, session: URLSession = nonCachedSession) -> Authentication {
8088
let client = api(forDomain: domain, session: session)
8189
return RSAAuthentication(api: client, enrollment: enrollment)
8290
}
@@ -100,7 +108,7 @@ public func authentication(forDomain domain: String, andEnrollment enrollment: E
100108

101109
- seealso: Guardian.Authentication
102110
*/
103-
public func authentication(url: URL, andEnrollment enrollment: Enrollment, session: URLSession = .shared) -> Authentication {
111+
public func authentication(url: URL, andEnrollment enrollment: Enrollment, session: URLSession = nonCachedSession) -> Authentication {
104112
let client = api(url: url, session: session)
105113
return RSAAuthentication(api: client, enrollment: enrollment)
106114
}
@@ -149,7 +157,7 @@ public func authentication(url: URL, andEnrollment enrollment: Enrollment, sessi
149157

150158
- returns: a request to create an enrollment
151159
*/
152-
public func enroll(forDomain domain: String, session: URLSession = .shared, usingUri uri: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
160+
public func enroll(forDomain domain: String, session: URLSession = nonCachedSession, usingUri uri: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
153161
let client = api(forDomain: domain, session: session)
154162
return EnrollRequest(api: client, enrollmentUri: uri, notificationToken: notificationToken, keyPair: keyPair)
155163
}
@@ -198,7 +206,7 @@ public func enroll(forDomain domain: String, session: URLSession = .shared, usin
198206

199207
- returns: a request to create an enrollment
200208
*/
201-
public func enroll(url: URL, session: URLSession = .shared, usingUri uri: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
209+
public func enroll(url: URL, session: URLSession = nonCachedSession, usingUri uri: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
202210
let client = api(url: url, session: session)
203211
return EnrollRequest(api: client, enrollmentUri: uri, notificationToken: notificationToken, keyPair: keyPair)
204212
}
@@ -246,7 +254,7 @@ public func enroll(url: URL, session: URLSession = .shared, usingUri uri: String
246254

247255
- returns: a request to create an enrollment
248256
*/
249-
public func enroll(forDomain domain: String, session: URLSession = .shared, usingTicket ticket: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
257+
public func enroll(forDomain domain: String, session: URLSession = nonCachedSession, usingTicket ticket: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
250258
let client = api(forDomain: domain, session: session)
251259
return EnrollRequest(api: client, enrollmentTicket: ticket, notificationToken: notificationToken, keyPair: keyPair)
252260
}
@@ -294,7 +302,7 @@ public func enroll(forDomain domain: String, session: URLSession = .shared, usin
294302

295303
- returns: a request to create an enrollment
296304
*/
297-
public func enroll(url: URL, session: URLSession = .shared, usingTicket ticket: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
305+
public func enroll(url: URL, session: URLSession = nonCachedSession, usingTicket ticket: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
298306
let client = api(url: url, session: session)
299307
return EnrollRequest(api: client, enrollmentTicket: ticket, notificationToken: notificationToken, keyPair: keyPair)
300308
}

GuardianTests/APIClientSpec.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class APIClientSpec: QuickSpec {
3030

3131
override func spec() {
3232

33-
let client = APIClient(baseUrl: ValidURL, session: URLSession.shared)
33+
let client = APIClient(baseUrl: ValidURL, session: Guardian.nonCachedSession)
3434

3535
beforeEach {
3636
stub(condition: { _ in return true }) { _ in

0 commit comments

Comments
 (0)