[SECURITY] Fixed exploit in token types

Fixes an exploit due to missing check of token type used.

Fixes #1118 once merged.
Merge pull request #1125 from TheSerapher/issue-1118

[SECURITY] Fixed exploit in token types