Forum Discussion

cczinski's avatar
cczinski
Novice I
3 years ago

Howdy, was hoping someone might be able to help me

Howdy, was hoping someone might be able to help me with getting the OAuth2 working. I'm using NodeJS to create the token and hit the api, but I've been stuck at trying to get the signature correct. I'm not quite sure what I'm doing wrong when creating the signature. ```var jwtHeader = { 'alg': 'RS256', 'typ': 'JWT', 'kid': ck.keyid } var jwtData = { 'aud': ck.clientid, 'sub': 'apigee', 'iss': ck.issuer, 'iat': currentTimestamp, 'exp': currentTimestamp + 3600 } const b64Header = toBase64 (jwtHeader); const jwtB64Header = replaceSpecialChars(b64Header); const b64Payload = toBase64 (jwtData); const jwtB64Payload = replaceSpecialChars (b64Payload); const toSign = jwtB64Header + '.' + jwtB64Payload const sign = crypto.createSign('SHA256') sign.update(toSign) const verify = crypto.createVerify('SHA256'); verify.update(toSign) const signature = sign.sign({key: privateKey, passphrase: 'passwordhere'}) console.log("Verified?") console.log(verify.verify(publicKey, signature, 'SHA256')); const token = toSign + "." + replaceSpecialChars(toBase64(signature));```
No RepliesBe the first to reply