tymondesigns / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.28k stars 1.55k forks source link

Token Generated from System.IdentityModel.Tokens.Jwt Microsoft throwing "Invalid Token" #1667

Open praveenrengarajan opened 6 years ago

praveenrengarajan commented 6 years ago

Subject of the issue

Jwt token generating in C# IdentityModel(Microsoft.IdentityModel) V5.2.2 and verifying that token in Laravel rest call jwt-auth (V1.0), it's throwing "Token Invalid" Exception. Encrypt key and other claims are same, but jwt-auth library failed to decode it. Encrypt Key: xfoSiRSaetjS9eEJ7ixGx9dYZB4nqaW3 Jwt Token: "ew0KICAiYWxnIjogIkhTMjU2IiwNCiAgInR5cCI6ICJKV1QiDQp9.ew0KICAiZW1waWQiOiAiMDAwMSIsDQogICJlbWFpbCI6ICJwcmF2ZWVuLnJAZ21haWwuY29tIiwNCiAgImZpcnN0bmFtZSI6ICJwcmF2ZWVuIiwNCiAgImxhc3RuYW1lIjogInIiLA0KICAic3ViIjogInByYXZlZW4uciIsDQogICJhdWQiOiAiaHR0cDovL3ByYXZlZW5yZW5nYXJhamFuLmNvbSIsDQogICJyb2xlcyI6ICJ7fSIsDQogICJuYmYiOiAxNTM3MzU2NDUzLA0KICAiZXhwIjogMTUzNzk2MTI1MywNCiAgImlhdCI6IDE1MzczNTY0NTMsDQogICJpc3MiOiAiaHR0cHM6Ly9wcmF2ZWVucmVuZ2FyYWphbi5jb20iDQp9.Gurbz9eHisFgydIw-XuoaNXO38z4z9AOr5BBdqg0fWw"

Is generated JWT token from Microsoft.IdentityModel wrong? or anything I missed?

Your environment

Q A
Bug? no / yes
New Feature? no / yes
Framework Laravel
Framework version 5.x.y
Package version 1.x.y
PHP version 5.x.y / 7.x.y

Steps to reproduce

Use above JWT token and encrypt key to decrypt/authenticate token.,

Expected behavior

The token should be valid.

Actual behavior

Invalid token exception

shooka commented 6 years ago

The decoded token is missing the jti claim which is required by default in the config file.

A TokenInvalidException will be thrown if any of these claims are not present in the payload.

'required_claims' => ['iss', 'iat', 'exp', 'nbf', 'sub', 'jti'],
praveenrengarajan commented 6 years ago

@shooka added jti in claims with random guid. still same issue while validating "Invalid Token"

brentschmaltz commented 6 years ago

@praveenrengarajan what error are we getting?