I am encountering a perplexing issue while working with the ConnectyCube REST API for user management. My code successfully generates a signature for actions, such as creating an app session token, but when attempting to create a user session token, the server consistently returns an "unexpected signature" error.
Here's the method I use to generate the signature:
const getSignature = () => {
const nonce = Math.floor(Math.random() * 1000000);
const timestamp = Math.floor(Date.now() / 1000);
const stringForSignature = `application_id=${config.applicationId}&auth_key=${config.authKey}&nonce=${nonce}×tamp=${timestamp}`;
const signature = crypto.createHmac('sha1', config.authSecret).update(stringForSignature).digest('hex');
return { signature: signature, timestamp: timestamp, nonce: nonce };
}
The signature generation appears to work correctly, as I can successfully create an app session token using it:
const getAppSessionToken = async () => {
const signature = getSignature();
const response = await axios.post(
'https://api.connectycube.com/session', {
'application_id': config.applicationId,
'auth_key': config.authKey,
'nonce': signature.nonce,
'timestamp': signature.timestamp,
'signature': signature.signature
}, { headers: { 'Content-Type': 'application/json' } });
return response.data.session.token;
}
However, when attempting to create a user session token, the server responds with an "unexpected signature" error:
const createSessionWithLogin = async (emailAddress, password) => {
const signature = getSignature();
return await axios.post(
'https://api.connectycube.com/session',
{
'application_id': config.applicationId,
'auth_key': config.authKey,
'nonce': signature.nonce,
'timestamp': signature.timestamp,
'signature': signature.signature,
'user': {
'email': emailAddress,
'password': password
}
},
{
headers: {
'Content-Type': 'application/json'
}
}
);
}
I would appreciate any insights into what might be causing this issue or suggestions for troubleshooting. Thank you!
You can get user token by this code
Result