Skip to content

Commit

Permalink
fix: idToken generation
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Sep 17, 2024
1 parent 9d1ff3f commit 5ec723b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Tests/SingleFactorAuthTests/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct TestPayload: JWTPayload, Equatable {
case iat
case email
case audience = "aud"
case name
}

var subject: SubjectClaim
Expand All @@ -22,13 +23,15 @@ 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 {
try expiration.verifyNotExpired()
}
}


func generateRandomEmail(of length: Int) -> String {
let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var s = ""
Expand All @@ -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 {
Expand Down

0 comments on commit 5ec723b

Please sign in to comment.