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

Sending Security Tokens with Request

9 Answers 375 Views
ODataDataSource
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 23 Jun 2012, 04:47 PM
Is there a way to send tokens such as OAuth2 with the call to the ODataService?

I can see that there may be a way of injecting headers in the client-side event

OnRequesting but only if these are exposed in the args.set_Options object.



Thanks

Gary

9 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 28 Jun 2012, 10:36 AM
Hi Gary,

You can use the requesting event to extend the options object that is passed to the jQuery Ajax function. Here is short example:

<script type="text/javascript">
        function requesting(sender, args) {
            args.get_options().beforeSend = function(xhr) {
                xhr.setRequestHeader("Authorization", "GoogleLogin auth=" + token);
            }
        }
</script>


All the best,
Genady Sergeev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Gary
Top achievements
Rank 1
answered on 28 Jun 2012, 11:19 AM
Fantastic, that makes a secure and state-less Web API usable with the ODataDataSource. I will prototype this shortly!

0
Genady Sergeev
Telerik team
answered on 02 Jul 2012, 11:01 AM
Hello Gary,

Great news!

We will be glad if you share some feedback how it is going.

All the best,
Genady Sergeev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
ddkcoder
Top achievements
Rank 1
answered on 29 Oct 2012, 06:15 PM
Is there any more documentation on this functionality?  The reality is that most odata source exposed to the internet would require some sort of authentication.
0
Genady Sergeev
Telerik team
answered on 02 Nov 2012, 09:03 AM
Hi Gary,

As stated earlier, we expose the options object that is latter transferred to HTTP Post parameters. This means that you can hook on the requesting event and add whatever authentication you want. We will soon post a help article on the topic and will update this thread with a link.

Regards,
Genady Sergeev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Les
Top achievements
Rank 1
answered on 27 Feb 2013, 05:09 PM
It would be of great help if the following help topic article was available:
(Taken from the post below)
"We will soon post a help article on the topic and will update this thread with a link."
0
Gary
Top achievements
Rank 1
answered on 27 Feb 2013, 05:14 PM
It's actually simpler than I thought. We use a security Token here but you could use a user/password pair.
Call this straight after logon and it will apply to all JQuery Ajax calls
// Configure AJAX to have the security Token every call
  
$.ajaxSetup({
         'beforeSend': function (xhr) {
                 xhr.setRequestHeader("Authorization", "Basic " + $.fac.settings.securityToken);
         }
 });

 

 

Hope this helps.
Gary
0
Les
Top achievements
Rank 1
answered on 27 Feb 2013, 05:22 PM
I learn more by example and you mentioned a user/password pair and that is what I am looking for now.
How would you code the user/password in the setRequestHeader?
Thank!
0
Genady Sergeev
Telerik team
answered on 04 Mar 2013, 04:54 PM
Hello Les,

You simply need to add the security token as the value for the Authorization header. In turn, the security token should conform to the authentication type the underlying website is using. For example, the Basic authentication requires string in the format username:password that is encoded as Base64.

Kind regards,
Genady Sergeev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ODataDataSource
Asked by
Gary
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Gary
Top achievements
Rank 1
ddkcoder
Top achievements
Rank 1
Les
Top achievements
Rank 1
Share this question
or