2018-08-26 23:16:13 +01:00
/ * *
* @ author gchq77703 [ ]
* @ copyright Crown Copyright 2018
* @ license Apache - 2.0
* /
import Operation from "../Operation" ;
import jwt from "jsonwebtoken" ;
2018-08-31 13:58:06 +00:00
import OperationError from "../errors/OperationError" ;
2018-08-26 23:16:13 +01:00
/ * *
* JWT Decode operation
* /
class JWTDecode extends Operation {
/ * *
* JWTDecode constructor
* /
constructor ( ) {
super ( ) ;
this . name = "JWT Decode" ;
this . module = "Crypto" ;
2018-08-31 13:58:06 +00:00
this . description = "Decodes a JSON Web Token <b>without</b> checking whether the provided secret / private key is valid. Use 'JWT Verify' to check if the signature is valid as well." ;
this . infoURL = "https://wikipedia.org/wiki/JSON_Web_Token" ;
2018-08-26 23:16:13 +01:00
this . inputType = "string" ;
this . outputType = "JSON" ;
2018-08-31 13:58:06 +00:00
this . args = [ ] ;
2018-08-26 23:16:13 +01:00
}
/ * *
* @ param { string } input
* @ param { Object [ ] } args
* @ returns { JSON }
* /
run ( input , args ) {
try {
2018-08-31 13:58:06 +00:00
const decoded = jwt . decode ( input , {
json : true ,
complete : true
} ) ;
return decoded . payload ;
2018-08-26 23:16:13 +01:00
} catch ( err ) {
2018-08-31 13:58:06 +00:00
throw new OperationError ( err ) ;
2018-08-26 23:16:13 +01:00
}
}
}
export default JWTDecode ;