简体   繁体   中英

AngularJS NodeJS HTTPS requests

I'm a beginner in https & I developed an express example based on a certificate & key :

server = https.createServer(https_options, app).listen(PORT, HOST);

where https_options are the upmentioned security mechanism. My question is: how can I authenticate from angularjs services/factories when I'm calling expressjs api routes. Eg: routes.js :

app.get('/home', function(req, res) {
    res.send('welcome')
})

angular factory :

$http.get('/home').success(function(){}).error(function(){})

A simple example will do the work for me :) Thanks a lot !

Here is a good article using both Node with Express and AngularJs.

This article uses token based authentication. The authentication does not happen in your Angular app, but happens in Node, your Angular app just needs to know how to communicate with your Node API to authenticate users.

With token based authentication, in this case Json Web Tokens, a token is sent to your API on every request. Your API will then verify the token's authenticity and either grant or deny access to the user making the request.

Client certificates can be a solution. Authentication will be handled by the web browser, prompting the user to choose a certificate, rather than by your own script.

See this article for an example on how to implement this kind of authentication :

http://engineering.circle.com/https-authorized-certs-with-node-js/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM