简体   繁体   English

AngularJS NodeJS HTTPS请求

[英]AngularJS NodeJS HTTPS requests

I'm a beginner in https & I developed an express example based on a certificate & key : 我是https的初学者,我开发了一个基于证书和密钥的快速示例:

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

where https_options are the upmentioned security mechanism. 其中https_options是上述安全机制。 My question is: how can I authenticate from angularjs services/factories when I'm calling expressjs api routes. 我的问题是:当我调用expressjs api路由时,如何从angularjs服务/工厂进行身份验证。 Eg: routes.js : 例如: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. 是一篇使用Node with Express和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. 您的Angular应用程序中不会发生身份验证,但在Node中发生,您的Angular应用程序只需要知道如何与您的Node API进行通信以对用户进行身份验证。

With token based authentication, in this case Json Web Tokens, a token is sent to your API on every request. 使用基于令牌的身份验证(在本例中为Json Web Tokens),会在每次请求时将令牌发送到您的API。 Your API will then verify the token's authenticity and either grant or deny access to the user making the request. 然后,您的API将验证令牌的真实性,并授予或拒绝发出请求的用户的访问权限。

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. 身份验证将由Web浏览器处理,提示用户选择证书,而不是您自己的脚本。

See this article for an example on how to implement this kind of authentication : 有关如何实现此类身份验证的示例,请参阅此文章:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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