kylef / JSONWebToken.swift

Swift implementation of JSON Web Token (JWT).
http://jwt.io
BSD 2-Clause "Simplified" License
763 stars 226 forks source link

Sample code given in readme returns an error. #110

Open bibinjacobpulickal opened 6 years ago

bibinjacobpulickal commented 6 years ago

This is the sample code given for decoding a jwt gives an error "Failed to decode JWT: Unsupported algorithm or incorrect key", which is really undesirable from a developers perspective. I also, tried decoding my string that didn't work either do { let claims: ClaimSet = try JWT.decode("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.2_8pWJfyPup0YwOXK7g9Dn0cF1E3pdn299t4hSeJy5w", algorithm: .hs256("secret".data(using: .utf8)!)) print(claims) } catch { print("Failed to decode JWT: \(error)") } This was my string: "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2NhcGkuZGJzLmNvbSIsImlhdCI6MTUzMDI1MzE0MzIyOSwiZXhwIjoxNTMwMjU2NzQzMjI5LCJzdWIiOiJTVmN3TXpZPSIsInB0eXR5cGUiOjEsImNsbmlkIjoiY2xpZW50SWQyIiwiY2xudHlwZSI6IjIiLCJhY2Nlc3MiOiIxRkEiLCJzY29wZSI6IjJGQS1TTVMiLCJhdWQiOiJodHRwczovL2NhcGkuZGJzLmNvbS9hY2Nlc3MiLCJqdGkiOiI1OTc1OTE1ODk4MjQ1MDYwMjQ2IiwiY2luIjoiVXpFeE5USXlOREZHIn0.PnCyow4gk3-i5odLy81eJ_G-uU_DQAmkvWAIHpRraBQ" screen shot 2018-06-29 at 13 08 42