Skip to content

Commit f414798

Browse files
authored
Merge pull request #54 from inplayer-org/fix/change_internal_refresh_token_logic
Change internal refresh token logic.
2 parents 28c20cc + 88f7b01 commit f414798

File tree

147 files changed

+255
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+255
-168
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>BuildSystemType</key>
6+
<string>Original</string>
7+
<key>PreviewsEnabled</key>
8+
<false/>
9+
</dict>
10+
</plist>

Example/Podfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
source 'https://github.com/CocoaPods/Specs.git';
12
platform :ios, '10.0'
23

34
target 'Example' do

InPlayerSDK.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "InPlayerSDK"
19-
s.version = "1.5.8"
19+
s.version = "1.5.12"
2020
s.summary = "InPlayer's iOS API client wrapper."
2121

2222
# This description is used to generate tags and improve search results.

Source/Core/API/Account/INPAccountService.swift

+1
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ private enum AccountAPIRouter: INPAPIConfiguration {
488488
.forgotPassword,
489489
.authenticate,
490490
.authenticateClientCredentials,
491+
.refreshToken,
491492
.getRegisterFields,
492493
.getSocialURLs:
493494
return false

Source/Core/API/INPAuthHandler.swift

+24-8
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ final class INPAuthHandler: RequestInterceptor {
3434
var adaptedRequest = urlRequest
3535
if let authenticationType = adaptedRequest.value(forHTTPHeaderField: NetworkConstants.HeaderParameters.authenticationType),
3636
authenticationType == NetworkConstants.HeaderParameters.refreshToken {
37-
completion(.success(adaptedRequest))
38-
return
37+
return completion(.success(adaptedRequest))
3938
}
4039
guard
4140
let accessToken = InPlayer.Account.getCredentials()?.accessToken,
@@ -63,14 +62,31 @@ final class INPAuthHandler: RequestInterceptor {
6362
else {
6463
return completion(.doNotRetry)
6564
}
66-
requestToRetry.append(completion)
65+
66+
if let credentials = InPlayer.Account.getCredentials() {
67+
if Date().timeIntervalSince1970.isLess(than: credentials.expires) {
68+
69+
// token is not expired, but invalidated. Remove from storage and do not retry
70+
InPlayer.Account.removeCredentials()
71+
72+
return completion(.doNotRetry)
73+
} else {
74+
requestToRetry.append(completion)
6775

68-
if !isRefreshing {
69-
refreshTokens { [weak self] (succeeded, accessToken, refreshToken) in
70-
guard let strongSelf = self else { return }
71-
strongSelf.requestToRetry.forEach { $0(.retryWithDelay(0.25)) }
72-
strongSelf.requestToRetry.removeAll()
76+
if !isRefreshing {
77+
refreshTokens { [weak self] (succeeded, accessToken, refreshToken) in
78+
guard let strongSelf = self else { return }
79+
if succeeded {
80+
strongSelf.requestToRetry.forEach { $0(.retryWithDelay(0.25)) }
81+
} else {
82+
InPlayer.Account.removeCredentials()
83+
}
84+
strongSelf.requestToRetry.removeAll()
85+
}
86+
}
7387
}
88+
} else {
89+
return completion(.doNotRetry)
7490
}
7591
}
7692

Source/Core/API/NetworkDataSource.swift

-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class NetworkDataSource {
2323
route: INPAPIConfiguration,
2424
decoder: JSONDecoder = JSONDecoder(),
2525
completion: @escaping RequestCompletion<T>) {
26-
if route.requiresAuthorization, !session.isAuthorized {
27-
return completion(nil, InPlayerUnauthorizedError())
28-
}
2926

3027
session.request(route).validate().responseDecodable(decoder: decoder) { (response: DataResponse<T, AFError>) in
3128
switch response.result {

Source/Core/Account.swift

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public extension InPlayer {
2727
return UserDefaults.credentials
2828
}
2929

30+
/**
31+
Removes account and user credentials
32+
*/
33+
public static func removeCredentials() {
34+
UserDefaults.credentials = nil
35+
UserDefaults.account = nil
36+
}
37+
3038
/**
3139
Get account if logged in, else it returns nil
3240
- Returns: Account or nil

docs/Classes.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ <h4>Declaration</h4>
378378
</section>
379379
</section>
380380
<section id="footer">
381-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
381+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
382382
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
383383
</section>
384384
</article>

docs/Classes/InPlayer.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ <h4>Declaration</h4>
503503
</section>
504504
</section>
505505
<section id="footer">
506-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
506+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
507507
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
508508
</section>
509509
</article>

docs/Classes/InPlayer/Account.html

+28-1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,33 @@ <h4>Return Value</h4>
349349
</section>
350350
</div>
351351
</li>
352+
<li class="item">
353+
<div>
354+
<code>
355+
<a name="/s:11InPlayerSDK0aB0C7AccountC17removeCredentialsyyFZ"></a>
356+
<a name="//apple_ref/swift/Method/removeCredentials()" class="dashAnchor"></a>
357+
<a class="token" href="#/s:11InPlayerSDK0aB0C7AccountC17removeCredentialsyyFZ">removeCredentials()</a>
358+
</code>
359+
</div>
360+
<div class="height-container">
361+
<div class="pointer-container"></div>
362+
<section class="section">
363+
<div class="pointer"></div>
364+
<div class="abstract">
365+
<p>Removes account and user credentials</p>
366+
367+
</div>
368+
<div class="declaration">
369+
<h4>Declaration</h4>
370+
<div class="language">
371+
<p class="aside-title">Swift</p>
372+
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">static</span> <span class="kd">func</span> <span class="nf">removeCredentials</span><span class="p">()</span></code></pre>
373+
374+
</div>
375+
</div>
376+
</section>
377+
</div>
378+
</li>
352379
<li class="item">
353380
<div>
354381
<code>
@@ -1944,7 +1971,7 @@ <h4>Parameters</h4>
19441971
</section>
19451972
</section>
19461973
<section id="footer">
1947-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
1974+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
19481975
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
19491976
</section>
19501977
</article>

docs/Classes/InPlayer/Asset.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ <h4>Parameters</h4>
688688
</section>
689689
</section>
690690
<section id="footer">
691-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
691+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
692692
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
693693
</section>
694694
</article>

docs/Classes/InPlayer/Configuration.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ <h4>Declaration</h4>
373373
</section>
374374
</section>
375375
<section id="footer">
376-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
376+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
377377
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
378378
</section>
379379
</article>

docs/Classes/InPlayer/Notification.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ <h4>Declaration</h4>
427427
</section>
428428
</section>
429429
<section id="footer">
430-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
430+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
431431
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
432432
</section>
433433
</article>

docs/Classes/InPlayer/Payment.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ <h4>Parameters</h4>
607607
</section>
608608
</section>
609609
<section id="footer">
610-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
610+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
611611
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
612612
</section>
613613
</article>

docs/Classes/InPlayer/Subscription.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h4>Parameters</h4>
374374
</section>
375375
</section>
376376
<section id="footer">
377-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
377+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
378378
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
379379
</section>
380380
</article>

docs/Classes/InPlayerNotificationAPIManager.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ <h4>Declaration</h4>
346346
</section>
347347
</section>
348348
<section id="footer">
349-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
349+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
350350
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
351351
</section>
352352
</article>

docs/Classes/InPlayerSessionAPIManager.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ <h4>Declaration</h4>
346346
</section>
347347
</section>
348348
<section id="footer">
349-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
349+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
350350
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
351351
</section>
352352
</article>

docs/Enums.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ <h4>Declaration</h4>
462462
</section>
463463
</section>
464464
<section id="footer">
465-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
465+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
466466
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
467467
</section>
468468
</article>

docs/Enums/AccountType.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ <h4>Declaration</h4>
319319
</section>
320320
</section>
321321
<section id="footer">
322-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
322+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
323323
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
324324
</section>
325325
</article>

docs/Enums/InPlayerEnvironmentType.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ <h4>Declaration</h4>
346346
</section>
347347
</section>
348348
<section id="footer">
349-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
349+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
350350
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
351351
</section>
352352
</article>

docs/Enums/InPlayerNotificationStatus.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ <h4>Declaration</h4>
454454
</section>
455455
</section>
456456
<section id="footer">
457-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
457+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
458458
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
459459
</section>
460460
</article>

docs/Enums/NotificationType.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ <h4>Declaration</h4>
434434
</section>
435435
</section>
436436
<section id="footer">
437-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
437+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
438438
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
439439
</section>
440440
</article>

docs/Enums/PurchaseHistory.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ <h4>Declaration</h4>
346346
</section>
347347
</section>
348348
<section id="footer">
349-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
349+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
350350
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
351351
</section>
352352
</article>

docs/Enums/RegisterFieldType.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ <h4>Declaration</h4>
462462
</section>
463463
</section>
464464
<section id="footer">
465-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
465+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
466466
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
467467
</section>
468468
</article>

docs/Extensions.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ <h1>Extensions</h1>
278278
</section>
279279
</section>
280280
<section id="footer">
281-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
281+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
282282
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
283283
</section>
284284
</article>

docs/Extensions/Notification.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ <h4>Declaration</h4>
285285
</section>
286286
</section>
287287
<section id="footer">
288-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
288+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
289289
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
290290
</section>
291291
</article>

docs/Extensions/Notification/Name.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ <h4>Declaration</h4>
291291
</section>
292292
</section>
293293
<section id="footer">
294-
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-04)</p>
294+
<p>&copy; 2020 <a class="link" href="https://inplayer.com/" target="_blank" rel="external">InPlayer</a>. All rights reserved. (Last updated: 2020-01-16)</p>
295295
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.12.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
296296
</section>
297297
</article>

0 commit comments

Comments
 (0)