Note that there are some explanatory texts on larger screens.

plurals
  1. POSecurely Passing UserID from ASP.Net to Javascript
    primarykey
    data
    text
    <p>In the application I am currently developing we are using ASP.Net forms authentication to grant the user further access to the site. This site is targeted towards mobile users and as such we are attempting to be as hands off from the server as possible and make use of KnockoutJS to make the web service call and load the data so that the user can view it. </p> <p>Right now the webservice (REST service using GET method) requires the username in order to load the data specific to that user. I have this information on the server side (ASP.net) and I can easily access either <code>User.Identity.Name</code> or access the forms authentication cookie directly and pull the information.</p> <p>My problem is that I need to get the username from the server to the client so that the service call can be made. I have looked into doing this securely but so far have come up blank. Currently I am passing the username as a url parameter and parsing it out using JavaScript, with a check on the <code>Page_Load</code> method to verify the username in the url matches the logged in user.</p> <p>I need a way to secure pass a username from ASP.Net that has authenticated the user using form to the client side JavaScript so I can make a REST webservice call.</p> <p>EDIT: So after googling and meeting with my team lead I <em>think</em> we will be using an OAuth implementation similar to this example: </p> <p><a href="http://www.c-sharpcorner.com/UploadFile/surya_bg2000/secure-wcf-restful-service-using-oauth/" rel="nofollow noreferrer">http://www.c-sharpcorner.com/UploadFile/surya_bg2000/secure-wcf-restful-service-using-oauth/</a></p> <p>Also for anything else looking for the same answer I found this question very helpful in understanding OAuth:</p> <p><a href="https://stackoverflow.com/questions/6865690/whats-the-point-of-a-timestamp-in-oauth-if-a-nonce-can-only-be-used-one-time">What&#39;s the point of a timestamp in OAuth if a Nonce can only be used one time?</a></p> <p>Assuming everything is implemented correctly would it be more secure (totally secure, secure, or more insecure?) to instead pass the generated signature via an ASP tag as mentioned below? </p> <p>EDIT 2: After some more review and some more searching we finally decided on a framework and method of making this work. As it turns out OAuth isn't necessarily the answer here, this questions:</p> <p><a href="https://stackoverflow.com/questions/12632348/but-seriously-example-of-asp-net-webapi-implementation-including-oauth">But Seriously.... Example of ASP.NET WebAPI implementation including OAuth</a></p> <p>was a lot of help as well in figuring out how to make this work. What we are going to end up doing is generating the signature and putting in on the javascript and making the call like that. The signatures are going to be time sensitive and regenerated each time the user loads the page so very OAuth like but we arent implementing the full spec.</p> <p><strong>TL:DR</strong> Final solution was to generate a hash signature and put it on the page via ASP server tag &lt;% aspvar_here %> and use it to validate the service call</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload