Difference between revisions of "M4 API hash construction"

From Kolmisoft Wiki
Jump to navigationJump to search
(Created page with '=Description= In M2 MOR API methods we use '''hash''' parameter for better security. <br><br> =Generate hash= How to construct hash to authenticate data over API * Conc…')
 
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=Description=
=Description=


In [[M2 MOR API]] methods we use '''hash''' parameter for better security.  
In [[M4 API]] methods we use '''hash''' parameter for better security.  


<br><br>
<br><br>
=Generate hash=
=Generate hash=


Line 37: Line 38:
<br><br>
<br><br>


'''NOTE that all allowed params are put down in documentation of [[M2 MOR API]] methods'''
'''NOTE that all allowed params are put down in documentation of [[M4 API]] methods'''
 
= Examples =
 
Example of User Update Api hash string:


<code>
581asdfghjkl
</code>
* 581 - is user ID
* asdfghjkl - is API key
Such string should be used to generate SHA1 hash.
<br><br>
= Hash check =
This functionality is only available for administrator. Go to '''SETTINGS''' -> '''Setup''' -> '''Generate hash'''. Let's assume that API secret key is set to ''MORMOR''. Enter uri and click ''Generate'':
<br><br>
[[File:Generatehash.png]]
<br><br>
As it is written by the information icon, parameters are shown in the same order as they were when generating hash.
<br><br>
= Short guide how to generate hash in console =
To generate hash using the console, you should use:
<code>
echo -n "Variable1Variable2Variable3Variable4...VariableX" |  sha1sum | awk '{print $1}'
</code>
<br><br>
'''NOTE that in this case only VARIABLES should be used.'''
Variables should be used in the correct order. Order could be recognized only after trying this in GUI. GUI will show what is the correct Variables order to for generating hash using the console.
= Example =
[[File:Hash_Variables3.png]]
In this case the correct structure of the hash generating is this:
<code>
echo -n "Variable1Variable2Variable3Variable4Variable5Variable6Variable7" |  sha1sum | awk '{print $1}'
</code>


= See also =
= See also =


* [[M2 MOR API]]
* [[M4 API]]

Latest revision as of 11:09, 28 November 2022

Description

In M4 API methods we use hash parameter for better security.



Generate hash

How to construct hash to authenticate data over API

  • Concatenate all values you want to send into a single string. During hash generation you can order params the way you want, order in request line can be different.

For example. You want to get all answered calls of user 123 from 2009-09-09 00:03 till now. You must send user_id, period_start and calltype params.

>> time = "2009-09-09 00:03".to_time.to_i
=> "1252454580"
>> hash_string = "123" + time.to_s + "answered"  
=> "1231252454580answered"

  • Add API_Secret_Key to the end of hash_string

>> API_Secret_Key = "Very Sercet Key"
>> hash_string += API_Secret_Key
=> "1231252454580answeredVery Sercet Key"

  • Calculate SHA1 hash of hash_string

>> Digest::SHA1.hexdigest(hash_string) 
=> "b93c35d5c6183288322122561a3da7e09abb63b7"

  • Use this hash as a hash parameter in API calls.



NOTE that all allowed params are put down in documentation of M4 API methods


See also