From 5ec723bd201785cc07952c47ec9ac5ab4b2502c7 Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Tue, 17 Sep 2024 07:33:26 +0200 Subject: [PATCH] fix: idToken generation --- Tests/SingleFactorAuthTests/Utils.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Tests/SingleFactorAuthTests/Utils.swift b/Tests/SingleFactorAuthTests/Utils.swift index 8a9e2a6..27c5fb4 100644 --- a/Tests/SingleFactorAuthTests/Utils.swift +++ b/Tests/SingleFactorAuthTests/Utils.swift @@ -12,6 +12,7 @@ struct TestPayload: JWTPayload, Equatable { case iat case email case audience = "aud" + case name } var subject: SubjectClaim @@ -22,6 +23,7 @@ struct TestPayload: JWTPayload, Equatable { var issuer: IssuerClaim var iat: IssuedAtClaim var email: String + var name: String // call its verify method. func verify(using signer: JWTSigner) throws { @@ -29,6 +31,7 @@ struct TestPayload: JWTPayload, Equatable { } } + func generateRandomEmail(of length: Int) -> String { let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" var s = "" @@ -53,12 +56,21 @@ func generateIdToken(email: String) throws -> String { // Parses the JWT and verifies its signature. let today = Date() - let modifiedDate = Calendar.current.date(byAdding: .hour, value: 1, to: today)! + let modifiedDate = Calendar.current.date(byAdding: .minute, value: 2, to: today)! let emailComponent = email.components(separatedBy: "@")[0] let subject = "email|" + emailComponent - let payload = TestPayload(subject: SubjectClaim(stringLiteral: subject), expiration: ExpirationClaim(value: modifiedDate), audience: "torus-key-test", isAdmin: false, emailVerified: true, issuer: "torus-key-test", iat: IssuedAtClaim(value: Date()), email: email) + let payload = TestPayload( + subject: SubjectClaim(stringLiteral: subject), + expiration: ExpirationClaim(value: modifiedDate), // eat + audience: "torus-key-test", + isAdmin: false, + emailVerified: true, + issuer: "torus-key-test", + iat: IssuedAtClaim(value: today), + email: email, + name: email) let jwt = try signers.sign(payload) return jwt } catch {