Search code examples
iosswiftjwtxcode9json-web-token

Error "Failed to decode JWT: Unsupported algorithm or incorrect key" when I'm trying to decode my token on JSONWebToken's Framework


I have the following code:

if let user = response.result.value{
    do {
       let claims: ClaimSet = try JWT.decode(user.access_token, algorithm: .hs256(self.jwtSecret.data(using: .utf8)!))
       user.id = claims["sub"] as! Int
       user.iss = claims["iss"] as! String
       print(claims)
       } catch {
          print("Failed to decode JWT: \(error)")
          reject(error)
         }
}

But I have that error. Now when I'm validating on jwt.io I had a valid decodification. There's a picture of that validation:

enter image description here

So i dont understand what am I doing wrong. Any suggestion?

Best Regards


Solution

  • Your secret key isnt in base64.It should be base64.