Company
Date Published
Author
Max Lynch
Word count
882
Language
English
Hacker News points
None

Summary

In the era of single-page applications, AngularJS has become a leading framework, but traditional Web 2.0 authentication methods are no longer sufficient, necessitating new approaches such as cookie-based authentication and Cross-Origin Resource Sharing (CORS). CORS, supported by major browsers, allows access to services outside the current domain, although native web views like Cordova and Phonegap need domain whitelisting for security. Proper server configuration, including setting headers like Access-Control-Allow-Credentials, is crucial for session-based authentication. AngularJS facilitates remote API access via the $http service, and cookie storage can be enabled using the withCredentials flag. Cross-Site Request Forgery (CSRF) protection can be maintained by setting appropriate headers through AngularJS configurations. While cookie-based authentication is prevalent, token-based systems or HTTP Basic Authentication might better suit some APIs, offering alternatives to avoid cross-domain issues inherent to cookie methods.