Natkinson
2 months agoGenius
Error with Oauth 2.0 Client Credentials workflow
I'm trying to authenticate an api call in a typescript app using the oauth 2.0 client credentials workflow and I'm running into issues, I believe, with generating the CC Hash for this. This is for Community Classic. I have verified that I have the correct client id, client secret and shared secret key and that they're being pulled in correctly in my code. Not sure what I'm missing, but this is the error I see when I try to authenticate:
{"error":"Authorization or API call failed","details":"Failed to obtain access token. Status: 403. Response: {\"status\":\"error\",\"message\":\"cc_hash is invalid.\",\"data\":{\"type\":\"error_data\",\"code\":214,\"developer_message\":\"The decryption failed. ccHash is Invalid\",\"more_info\":\"\"},\"metadata\":{}}"}
Here's the relevant part of my Typescript code that's generating the CC Hash. Not sure if something is formatted incorrectly or what's not being generated correctly or causing it to return an invalid cc hash
function generateCCHash(clientId: string, clientSecret: string, sharedSecretKey: string): string {
try {
const epochTimeMinute = getEpochTimeMinute();
const nonce = generateNonce();
const strToHash = `${clientId}:${clientSecret}:${nonce}:${epochTimeMinute}`;
console.log("String to hash:", strToHash);
const hash = crypto.createHash('sha512');
hash.update(strToHash, 'utf8');
hash.update(sharedSecretKey, 'utf8');
const hashResult = hash.digest('hex');
console.log("Generated hash (cc_hash):", hashResult);
return hashResult;
} catch (error) {
console.error("Error generating CC-Hash:", error);
throw error;
}
}