Difference between revisions of "MOR API hash construction"

From Kolmisoft Wiki
Jump to navigationJump to search
 
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
=Description=
In [[MOR API]] methods we use '''hash''' parameter for better security.
<br><br>
=Generate hash=
How to construct hash to authenticate data over API  
How to construct hash to authenticate data over API  


<br><br>
* 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.
=General=
* Concatenate all values you want to send into a single string. '''Notice that order <u>when constructing hash</u> should be as params are listed in descriptions'''.
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.  
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.  


Line 30: Line 35:
* Use this hash as a hash parameter in API calls.
* Use this hash as a hash parameter in API calls.
----
----
<br><br>
<br><br>


= All allowed params =
'''NOTE that all allowed params are put down in documentation of [[MOR API]] methods'''
 
* user_id
* period_start
* period_end
* direction
* calltype
* device
* balance
* users
* block
* email
* mtype
* monitoring_id
* tariff_id
* u0
* u1
* u2
* u3
* u4
* u5
* u6
* u7
* u8
* u9
* u10
* u11
* u12
* u13
* u14
* u15
* u16
* u17
* u18
* u19
* u20
* u21
* u22
* u23
* u24
* u25
* u26
* u27
* u28
* ay
* am
* ad
* by
* bm
* bd
* pswd
* user_warning_email_hour
* pgui
* pcsv
* ppdf
* recording_forced_enabled
* i4
* tax4_enabled
* tax2_enabled
* accountant_type_invalid
* block_at_conditional
* tax3_enabled
* accountant_type
* tax1_value
* show_zero_calls
* warning_email_active
* compound_tax
* tax4_name
* allow_loss_calls
* tax3_name
* tax2_name
* credit
* tax1_name
* total_tax_name
* tax2_value
* tax4_value
* ignore_global_monitorings
* i1
* tax3_value
* cyberplat_active
* i2
* i3
* recording_enabled
* email_warning_sent_test
* own_providers
* a0
* a1
* a2
* a3
* a4
* a5
* a6
* a7
* a8
* a9
* s_user
* s_call_type
* s_device
* s_provider
* s_hgc
* s_did
* s_destination
* order_by
* order_desc
* only_did
* description
* pin
* type
* devicegroup_id
* phonebook_id
* number
* name
* speeddial
* s_user_id
* s_from
* s_till
* s_transaction
* s_completed
* s_username
* s_first_name
* s_last_name
* s_paymenttype
* s_amount_max
* s_currency
* s_number
* s_pin
* p_currency
* paymenttype
* tax_in_amount
* amount
* transaction
* payer_email
* fee
* id
* quantity
* callerid
* cardgroup_id
<br><br>


= Examples =
= Examples =
Line 187: Line 54:
= Hash check =
= Hash check =


There is a functionality available for admin user which lets to check what hash should be formed.


In address bar type, for example, <code>http://YOUR_SERVER_IP/billing/test/test_api?user_id=52&u=SUPERTALKAPPTEST&p=R2phaYuF&balance=100</code> where instead of numbers type appropriate values. Click ''Enter'' on your keyboard and a single string line will appear on your screen. For example, by typing <code>http://YOUR_SERVER_IP/billing/test/test_api?user_id=52&u=SUPERTALKAPPTEST&p=R2phaYuF&balance=100</code> we get hash:
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>6a850080246b950f8863dce74fb4099362b37d78</code>
<code>
echo -n "Variable1Variable2Variable3Variable4...VariableX" |  sha1sum | awk '{print $1}'
</code>
<br><br>
<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 =
* [[MOR API]]
* [[MOR API]]

Latest revision as of 13:44, 5 December 2013

Description

In MOR 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 MOR API methods

Examples

Example of User Update Api hash string:

581asdfghjkl

  • 581 - is user ID
  • asdfghjkl - is API key

Such string should be used to generate SHA1 hash.



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:

Generatehash.png

As it is written by the information icon, parameters are shown in the same order as they were when generating hash.



Short guide how to generate hash in console

To generate hash using the console, you should use:

echo -n "Variable1Variable2Variable3Variable4...VariableX" |  sha1sum | awk '{print $1}'



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

Hash Variables3.png

In this case the correct structure of the hash generating is this:

echo -n "Variable1Variable2Variable3Variable4Variable5Variable6Variable7" |  sha1sum | awk '{print $1}'

See also