Skip to content

Commit e532201

Browse files
authored
Merge pull request #241 from line/feature/login-manager-id-token-tests-enhancement
Enhance LoginManager ID token testing with dependency injection
2 parents a8b63e3 + be192ed commit e532201

File tree

2 files changed

+487
-5
lines changed

2 files changed

+487
-5
lines changed

LineSDK/LineSDK/Login/LoginManager.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ public final class LoginManager: @unchecked Sendable /* Sendable is ensured by t
243243
token.IDToken!,
244244
providerMetadata: providerMetadata,
245245
process: process,
246-
userID: profile?.userID
246+
userID: profile?.userID,
247+
currentDate: Date()
247248
)
248249
}
249250

@@ -404,7 +405,10 @@ extension LoginManager {
404405
func verifyIDToken(
405406
_ token: JWT,
406407
providerMetadata: DiscoveryDocument.ResolvedProviderMetadata,
407-
process: LoginProcess, userID: String?) throws
408+
process: LoginProcess,
409+
userID: String?,
410+
currentDate: Date = Date()
411+
) throws
408412
{
409413

410414
try token.verify(with: providerMetadata.jwk)
@@ -417,10 +421,9 @@ extension LoginManager {
417421
}
418422
try payload.verify(keyPath: \.audience, expected: process.configuration.channelID)
419423

420-
let now = Date()
421424
let allowedClockSkew: TimeInterval = 5 * 60
422-
try payload.verify(keyPath: \.expiration, laterThan: now.addingTimeInterval(-allowedClockSkew))
423-
try payload.verify(keyPath: \.issueAt, earlierThan: now.addingTimeInterval(allowedClockSkew))
425+
try payload.verify(keyPath: \.expiration, laterThan: currentDate.addingTimeInterval(-allowedClockSkew))
426+
try payload.verify(keyPath: \.issueAt, earlierThan: currentDate.addingTimeInterval(allowedClockSkew))
424427
try payload.verify(keyPath: \.nonce, expected: process.IDTokenNonce!)
425428
}
426429
}

0 commit comments

Comments
 (0)