Skip to content

IAT is an int but it says it's not #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
flowbe opened this issue May 30, 2015 · 4 comments
Closed

IAT is an int but it says it's not #9

flowbe opened this issue May 30, 2015 · 4 comments
Labels

Comments

@flowbe
Copy link

flowbe commented May 30, 2015

Hello,

When I decode my JWT I got this error:

Decode Error: Issued at claim (iat) must be an integer

But the problem is that the iat is actually an integer. If I do a println of payload[key] in the validateDate function, it returns: Optional(1433003301)

What is the problem ?

@kylef
Copy link
Owner

kylef commented May 30, 2015

@TheFlow95 Would you be able to share with me an example JWT that exhibits this problem.

@kylef kylef added the bug label May 30, 2015
@flowbe
Copy link
Author

flowbe commented May 31, 2015

My JWT:

eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE0MzMxNjg0NzgsInVzZXJuYW1lIjoiZmxvcmVudGluIiwiaWF0IjoiMTQzMzA4MjA3OCJ9.bONP-CgEDBWi_wcoxX84a-vm3-fksgIinUQ-5j9QnlMyquOR1xCevnkQcIWbkISI_JHEcoys5jOfxyM_An-4A1Z5r98bb8YaK7L2vOfenQOmFV9Trj0yLlB3SiGAE6Ck-vCC9b-Zto6bLurRGUN13TpwkiadJh9kBd4raZFGLPcC4D6hndL9a7-39g3g36tfYiahjwzStRVfVxoHo9LKqUwna9o574I0svglc4IvmzssH6NE8Q7RISG7Q5i-5mTVyjyAxdZK1VNsyEwkcqoh4uRQc91pztPjFNa9cJu-uLnhqLI__oJLbWUtY6PvHjUaMFQ-l2fHUxMdFEuPeia9EpB13bPVIiJzMlTd0JNmIK7qHGcg0kuBUR-6ZwHgSXaNcn3SGBD0ZG3loJi2l9qSXvMRfzdiu6xOJozTf-YTRTWD3brg3Z64vb3U9I7Ieuh_vJO6qY0uBNX4hl0fnqpZXDfKX-rX_UmsUpjAOxCQCjyejeoJCimZ1yCa4xa-yQiBeBEK0k265hyTJZpxQ9Iscl4GxCCrDeNRZ4EY4sb_8WKj_XqOPt-lfS45EhUmsrGHkOu0n2CNq6T-bOroG5Q95plHnV9wT5R3kAA_XwnvRlon7tC1NmnJTxLiYAAG0ZK483H6hPluspRXOyDPjabFe6gyUwAsclnT4HDKJ5rEjQI

I found a trick to make it work:

func validateDate(payload:Payload, key:String, comparison:NSComparisonResult, failure:InvalidToken, decodeError:String) -> InvalidToken? {
if let timestamp = payload[key] as? NSTimeInterval {
let date = NSDate(timeIntervalSince1970: timestamp)
if date.compare(NSDate()) == comparison {
return failure
}
} else if let timestamp = (payload[key] as? String)?.toInt() {
let date = NSDate(timeIntervalSince1970: Double(timestamp))
if date.compare(NSDate()) == comparison {
return failure
}
} else if let timestamp:AnyObject = payload[key] {
return .DecodeError(decodeError)
}
return nil
}

But the algorithm (RS256) is not supported by your project. Can you add it please ?

@kylef
Copy link
Owner

kylef commented Jun 3, 2015

@TheFlow95 Your JWT is improperly encoded. Take a look at the payload:

{
  "exp": 1433168478,
  "username": "florentin",
  "iat": "1433082078"
}

Note, IAT is a string instead of an integer as per the JWT specification where it states the value must be a number (not a string).

Its value MUST be a number containing a NumericDate value

Your exp value is properly encoded as a number, I'd suggest you do the same for your iat value.

@kylef
Copy link
Owner

kylef commented Jun 3, 2015

There's issue #6 tracking RS256 support. I'd welcome any pull request implementing this.

@kylef kylef closed this as completed Jun 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants