This is a migrated thread and some comments may be shown as answers.

How can I add HMAC token to HTML header

3 Answers 261 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 12 Apr 2012, 03:59 PM
How can we add data to the HTML headers sent by the data source?
Is there a function or property that will do this?

Something like this would be a simple fix as JQuery 1.5.* supports adding
a "headers" map to add any custom headers you want.

                        transport: {
                            read: "http://localhost/WebAPITest/api/Transactions",
                            datatype: "json",
                            headers: { Authorization: "user/password" }
                        },

Thanks

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 13 Apr 2012, 04:47 PM
Hi,

This can be done like this:

transport: {
  read: {
    headers: {
      Authorization: "user/password"
    },
    dataType: "json"
  }
}



The reason this works is because all settings specified in the transport's read, update, destroy and create fields are passed to jQuery.ajax.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gary
Top achievements
Rank 1
answered on 13 Apr 2012, 06:51 PM
Ok I have tried this (key without quotes),

transport: {                            
    read: "http://localhost/TestWebAPI/api/Transactions",                            
    headers: { Authorization: "Basic 7kaiuuqtdw7" },                            
    datatype: "json"                        
}

and this (key with quotes),

transport: {                             
    read: "http://localhost/TestWebAPI/api/Transactions",                             
headers: { "Authorization""Basic 7kaiuuqtdw7" },                             
datatype: "json"                         
}

but do not see the header in the request:

GET /TestWebAPI/api/Transactions?take=10&skip=0&page=1&pageSize=10 HTTP/1.1
X-Requested-With: XMLHttpRequest
Accept: */*
Referer: http://localhost/TestWebAPI/Transactions.htm
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Host: localhost
Connection: Keep-Alive
Cookie: CompositeVersionString_-7163923_757602046=2.1.4113.99; CompositeVersionString_-412511224_757602046=2.1.4113.99; CKFinder_Path=Images%3A%2F%3A1; CKFinder_Settings=TNNDS

No sign of an Authorization Header.

Any other ideas?
0
Gary
Top achievements
Rank 1
answered on 13 Apr 2012, 07:19 PM
Actually I mis-read your code. So added the Outer "Read" property
Tried this as you said:
transport: {                             
    read: {                                 
        read: "http://localhost/WebAPITest/api/Transactions",                                 
        headers: {                                     
            Authorization: "Basic 872372jhsqhsojh"},                                 
            dataType: "json"                             
    }                         
}

Failed!. The second read should be "url:".
transport: {                            
    read: {                                
        url: "http://localhost/WebAPITest/api/Transactions",                                
        headers: {                                    
            Authorization: "Basic 872372jhsqhsojh"},                                
            dataType: "json"                            
    }                        
}

Great, now I can implement security at the method level but using the transport.
Thanks for the help
Gary
Tags
Data Source
Asked by
Gary
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Gary
Top achievements
Rank 1
Share this question
or