You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello thank you so much for creating this library. I have been working on a problem where I was not able to have success with signing my JWT. The following is my code:
let teamID = some value
let keyID = some value
let authToken = """
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCoknaik3X9AwXf
1nb/BfHlR4RBcij+Ri2RzxZfdcTuhcIL4XLrgwaz/Skx3R/UjU3eoxneBjcGeA7X
QX75aXMS2FKrfQEJ6mp9AVQTowPC5VkAp8L8vk/cBrckZFHQsm9bHnLirJ6LYhWK
sLbvgpJo+P4OMG4P/GeQVwaWwLxaZNSs0sEjVRuy0vbWCO4jJwnmZpPMxU0sRCRN
xod3n6DJ0XhwCP/CxhlFVHjoM/nX/HGlPWkwG05BFBH4J9Zy4SNNNg6CDjIsl56R
2Fu8d/RHtIB/UPhIEoV6t5rWkJx4SP76OwjiXl9IGiDWpb6uu2/OQctZRBezxvCZ
O4lgzKFXAgMBAAECggEAYK4XsmhmbCTWsqka+GqdcIVS2gIydpsjOZQO3dL6jl5S
i2PS+DXem04f2URcJBiix4S9qjPgTSqAQH6E52DOKcm9qDL6bIhwaJ9hbB27Y4UM
Ra7xyukPfj6vvQR4U/xyl0zgURb1mzU266MsWDOH6wKbGuI1zZ9SelsfIUkK/cAV
s6Ao4kzCCQWZMQ/GkYxtQXg/tdPtI2Ueexon0Xtr4bc50XefEFvpKNi3ZqX7fRHV
e2bvnzKH6TN6DlEBruIdRwLsfmFXMIXU98D1OYokaaeVeHH5iZ2nXrlGGw72RfcQ
awrEHvMTTUhzg5LnMw30Smq1ogPanhLtbofPqIQJwQKBgQDfxKZ7lFle+tiMEKmU
87uiRavAHrmQNipqBcbtadJqqQtvGOCxwSg9phh2YnwxRSyw1oBpg4ogvg1QbhqV
UNfB8b/M2kpPRpGZpjCvi6En8GzK6K4e/UQJ4i0l7tPT9tt3TynbMwb3xFcEnFEX
IxfcWnlbC5tm5Sea6b4BzwK84QKBgQDA2nvqHNsqU9HyCX61R5Bo2QLnsI4CgUBk
z2hhc4bteb//mKCWeVvPNRu9AFhNEJzix0/EEkCVhbpIKE1DUCzBPWI/4CkH1bRc
RBE7/7I3pcMBbV22OdGoISmUf6IFZSyQuBoShLDBH3CVmqdmto9b5nwYaTgdycvt
xpyQvdKtNwKBgHFzF2EyXnlcPqwMyp29URU9s41NRpGKFMj6MtgtvcPb/vMNruYQ
Y2GWM3LaDdNBGh5yMlrMmRxunvt3Rz0K5sjq025+AgzdX3aCHs7xwPwp1k6t15HY
oEVOictgob8mujBsT3FWFqNJxUCOLELJxRAwQrTZVqm9Zu4Qsgfit6WhAoGBAKWx
UbOUNU0JlSDBvaacpNsgUFmlnG1UhXHXrVPFAVE5QJeml5qRDCtb8sgQ6szTkCdb
nRHVqL2Olrz2O2OxF7KzPZ2pxzbfCkYXiUMmbgVXmtK4F0LALHyqeWIHwrml8oMo
WeY9MOvMSluO83LRORx5S3dht4AIZ/iTouLM5JxDAoGAcAnam49TeCFZuOu5/QCb
GYyAntOQL/nunSbuHoNvC+bBrcUX2BfDkalkzlm/YRJgmqSQ7Ih3fbp4i5NCVtpM
1dafoyed5UqY0F7Vou7JJE57tlKieKPhQOMTSl2Q5WMvby+owRb0Sx325xQvoslH
QM9+y6wy6YMdNweC+JkcZVo=
-----END PRIVATE KEY-----
"""
func generateToken() {
let myHeader = Header(kid: keyID)
let urlString = "https://www.googleapis.com/oauth2/v4/token"
let claims = JWTClaims(iss: teamID, iat: Date(), exp: Date() + 3.0, scope: "devstorage.read_write", aud: urlString)
var jwt = SwiftJWT.JWT(header: myHeader, claims: claims)
guard let tokenData = authToken.data(using: .utf8)?.base64EncodedData() else {
return
}
var jwtSigner = JWTSigner.rs256(privateKey: tokenData)
do {
let token = try jwt.sign(using: jwtSigner)
print(jwt)
UserDefaults.standard.setValue(token, forKey: "JWT")
} catch {
print(error.localizedDescription)
}
}
}
struct JWTClaims: Claims {
let iss: String
let iat: Date?
let exp: Date?
let scope: String
//let aud: URL
let aud: String
}
If I po to the debugger try jwt.sign(using: jwtSigner) it gives me the error "The provided key did not have the expected PEM headers/footers".
What am I missing here? I have checked my header and payload seem to be in the correct format.
The text was updated successfully, but these errors were encountered:
Make sure you are using proper JWTSigner type while signing the JWT in the final step. I was using wrong JWTSigner and that caused the problem. Thanks.
On Tue, 19 Sep 2023 at 15.15 Dhaval Nena ***@***.***> wrote:
Make sure you are using proper JWTSigner type while signing the JWT in the
final step. I was using wrong JWTSigner and that caused the problem. Thanks.
—
Reply to this email directly, view it on GitHub
<#114 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEHAXXVTTG4YWJMVJZWUE6TX3FA73ANCNFSM6AAAAAAYVW3VLE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
Hello thank you so much for creating this library. I have been working on a problem where I was not able to have success with signing my JWT. The following is my code:
If I po to the debugger
try jwt.sign(using: jwtSigner)
it gives me the error "The provided key did not have the expected PEM headers/footers".What am I missing here? I have checked my header and payload seem to be in the correct format.
The text was updated successfully, but these errors were encountered: