mvc api security

ITsolutionWizard
ITsolutionWizard used Ask the Experts™
on
Assume I have super simple MVC API. Our customer will use html jquery to consume the API.
I want to add one token per customer. for example,


customer A token: asdfasdfasfasfasd
customer B token: 23423423423234dsf


1. If the customer's webpage put above token there to consume my API, it has security concern because I can see the token in view source.
2. What is the simple way to implment API with token? I only have 2 to 5 API so I do not need very complex one.

[System.Web.Http.HttpGet]
        public string Get(string firstname)
	{
return firstname;

}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
I'm not sure what you mean with "I can see the token in the view source", as you are the server and programmer, how is that an issue?
Anyway, if you want to make it more secure, the session HAS to start with a login form. After hashing, salting and checking against the user database, and the login is successful, issue a cookie and check this cookie for the rest of the session.
Obviously, you probably need 5 times the amount of code you didn't expect you'd need. But with any time of security, you'll have to do some more work.

Author

Commented:
Thank You. But let me tell you more in details.
All I need is to give API - end point to our customer. It is actually the company. I will give them end point and token so their company develop can consume our API using e.g. jquery ajax to consume/read the information through API.

No one will login in this situation.
Jose Gabriel Ortega CastroTop Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018

Commented:
The solution is to use a "POST" call instead of a GET :)

[HttpPost]

        public string Get(string firstname)
	{
//validate request and token as header then return
return firstname;

}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial