asp.net - how to implement the authentication in Single Page Application? -
as title says,i want build app run in browser single html page.but how implement authentication.and solution is:
- the server-side restful apis,which can used multiple platform,web ,mobile side ,etc.and every api need auth token parse,if api not token return 401.
- cuz first practise in browser,so need request token login,and when app needs request auth-apis,i put token in header requesting...
and questions : does safe enough? other better solution?
no it's not safe enough if token accessible through javascript same reason should set cookies http , restrict ssl. if hacker can inject javascript app, can steal token , use machine.
for reason suggest use secure, http cookie instead of token when using website.
if api going accessed native mobile app add token each url.
having custom header in http request might cause issues proxies might not pass headers through. cookie nothing more standardised http header might reuse that.
what consider using oauth if you're going allow 3rd party apps access parts of api.
there no reason why not use cookies browser based clients , apikey query parameter other clients.
Comments
Post a Comment