在认证离子/科尔多瓦应用 [英] Authentication in Ionic/Cordova App

查看:171
本文介绍了在认证离子/科尔多瓦应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我不是职业球员。

First off, I'm no pro.

在我的追求成为一个更好的开发者,我想了解需要什么以及如何完成创建离子的框架应用了注册/登录。

In my quest to become a better developer I am trying to understand what is needed and how to accomplish creating a sign-up/login for an Ionic-Framework app.

大多数单页的应用程序(的SPA),其也用作了用于客户端的HTML中的节点服务器上手柄的身份验证。在我的情况下,手机本身将煮好的HTML,所以我猜我可能对一些问题CORS系统可以往上走。

Most of the single-page-applications (SPAs) handle authentication on a node server that is also serving up the HTML for the client. In my case the phone itself will be serving up the HTML so I am guessing I may be going up against some CORs issues.

据我所知,离子-框架使用状态且基于角客户端-auth的回购我每当我在我的应用程序更改状态进行验证。

I understand that the Ionic-Framework uses states and based angular-client-side-auth repo I should be authenticating whenever I am changing states in my app.

我有一个初步的应用程序设置,但现在我也有点糊涂哪里从这里走了。

I have an initial app setup but now I am kind of confused where to go from here.

我在我手上的工具:


  • 的Node.js服务器-Thanks DigitalOcean(我应该使用这个作为一个代理我的数据库?)

  • CouchDB的服务器(这里全栈我们来)

我的问题:


  1. 什么是混合使用应用程序时进行身份验证的标准方法?

  2. 我应该如何使用Node.js作为代理到数据库?

  3. 我应该跳过的Node.js并直接与CouchDB的服务器进行身份验证? (我听说过此事)

  4. 我要对所有这一切错误的方式?

  5. 什么是我潜在的路障?

  6. 如何CORS与混合应用工作的?

  7. 什么我失踪?

感谢您帮助我成为一个更好的开发者。

Thanks for helping me become a better developer.

推荐答案

好了很多孤单回答。但是简单的答案是
只是让事情变得简单,像使用普通的Web应用程序进行身份验证。

Okay theres alot to answer. But the short answer is to just keep things simple and authenticate like you would a regular web app.

在常规的Web应用程序:


  • 在一个普通的web应用程序,你会发送到服务器的请求,并检查证书与数据库对用户进行认证

在移动应用程序:


  • 在一个移动应用程序,你会做通过Ajax请求相同的(在角度的情况下使用$ HTTP)。

  • 验证完成后在服务器上发送一个响应返回给指示前端的认证结果的应用程序(如JSON / XML)。

标准是什么方法呢?


  • 我不知道有关标准,但是这似乎是最简单的方法。标准随时更改,因为总有更好的方式来做到这一点。因此,只要能够完成任务去了,改善它更高版本。

我应该如何使用Node.js作为代理的DATABSE?


  • 我没有用太多的的NodeJS,所以我不知道你真正的意思。但是,如果它有助于了解 - 我使用PHP的接收Ajax请求的服务器上,处理与mysql数据库中的身份验证和返回到移动应用程序的响应。

我要对所有这一切错误的方式?


  • 我还没有看到你的初始设置。至于验证,只要你的应用程序改变状态的话,你可以使用localStorage的存储成功登录后,用户信息。在注销清除localStorage的。因此,所有你需要做的是检查是否在localStorage的存在​​,以确认用户是否​​登录的值。

我有什么潜在的路障?


  • 我建议你开始做你的应用程序,你就会知道很快。对整个离子+科尔多瓦使事情变得非常简单,除去大部分路障进行应用开发。

如何与CORS系统混合应用工作的?


  • 科尔多瓦允许默认跨域请求,所以你不会有跨域请求任何问题,这样的话你可以直接访问您的服务器进行认证。

什么我失踪?


  • IonicFramework 只是一个前端的HTML5框架。它本身并不能使你成为一个移动app.It只会给你很好的用户界面的工作。 IonicFramework为您提供了一些不错的的JavaScript功能它实现了采用了棱角分明。因此,为了获得最大的离子型的,你应该精通angularJs。学习的角度是非常值得的努力,以便去了。

  • IonicFramework is just a front end HTML5 framework. It alone cannot make you a mobile app.It will just give you nice UI to work with. IonicFramework provides you with some nice javascript features which it implements using angular. Thus, to get the most out of ionic you should be proficient with angularJs. Learning angular is well worth the effort so go for it.

实际的应用程序是由科尔多瓦编译。科尔多瓦采用常规的HTML / CSS / JavaScript文件和它们打包
到了Android APK或iPhone IPA,使它们可以安装在
相应的操作系统为本地应用。

The actual app is compiled by Cordova. Cordova takes your regular html/css/javascript files and packages them into the android apk or iphone ipa so that they can be installed on the respective os as native apps.

科尔多瓦是什么将允许您访问像摄像头,多媒体资料,通讯录本地电话功能
等等。

Cordova is what will allow you to access native phone features like the camera,gallery,contacts etc.

基于令牌认证 :我相信是一个另类。这是处理身份验证,现在是容易获得一个更清洁,更安全的方式。

Token Based Authentication : i believe is an alternative. It is a cleaner and more secure way of handling authentication that is now easily available.

有关详细信息,请查看以下链接:

For more information check out the following links:

  • Angular jwt (for apps using angular on the front-end)
  • Video Talk :Making your apps secure using JWT (by the creators of jwt.io)
  • Jwt.io (official website of jwt)
  • Jwt-Auth for Laravel ( For those using Laravel on the back end)

什么是使用基于令牌的方法的好处是什么?

跨域/ CORS:饼干+ CORS不要在不同的领域发挥出色。基于令牌的方法可以让你做AJAX调用到任何服务器,在任何领域,因为你使用的HTTP标头传输的用户信息。
无国籍(亦称服务器侧的可扩展性):没有必要保持一个会话存储器,令牌是传送所有的用户信息的自contanined实体。的状态的其余住在客户端上的cookie或本地存储

Cross-domain / CORS: cookies + CORS don't play well across different domains. A token-based approach allows you to make AJAX calls to any server, on any domain because you use an HTTP header to transmit the user information. Stateless (a.k.a. Server side scalability): there is no need to keep a session store, the token is a self-contanined entity that conveys all the user information. The rest of the state lives in cookies or local storage on the client side.

CDN::您可以为您的应用程序从一个CDN(如JavaScript的,HTML,图像等)的全部资产,你的服务器端仅仅是个API。
去耦:你是不依赖于特定的认证方案。可能在任何地方产生的记号,因此您的API可以从任何地方调用验证这些电话的方式单一。

CDN: you can serve all the assets of your app from a CDN (e.g. javascript, HTML, images, etc.), and your server side is just the API. Decoupling: you are not tied to a particular authentication scheme. The token might be generated anywhere, hence your API can be called from anywhere with a single way of authenticating those calls.

移动准备:当你开始工作的一个原生平台(iOS,Android版的Windows 8等)消费安全的API时,cookie是不理想的(你要处理的cookie容器) 。采用基于令牌的方法简化了这个有很多。
CSRF:因为你不是靠饼干,你并不需要,以防止跨站请求(例如,它不可能到你的网站,生成一个POST请求,并重新使用现有的身份验证Cookie,因为将有没有)

Mobile ready: when you start working on a native platform (iOS, Android, Windows 8, etc.) cookies are not ideal when consuming a secure API (you have to deal with cookie containers). Adopting a token-based approach simplifies this a lot. CSRF: since you are not relying on cookies, you don't need to protect against cross site requests (e.g. it would not be possible to your site, generate a POST request and re-use the existing authentication cookie because there will be none).

性能:我们并不presenting这里任何硬PERF基准,而是一个网络往返(如发现数据库会话)可能需要更多的时间比计算的HMACSHA256来验证令牌,并分析其内容。

Performance: we are not presenting any hard perf benchmarks here, but a network roundtrip (e.g. finding a session on database) is likely to take more time than calculating an HMACSHA256 to validate a token and parsing its contents.

登录页面是不是一个特例:如果您正在使用量角器来写你的功能测试,你不需要办理任何登录特殊情况。
标准型:您的API可以接受一个标准的JSON网络令牌(JWT)。这是一个标准,有多个后端库(.NET,Ruby中,使用Java,Python,PHP)和公司支持他们的基础设施(如火力地堡,谷歌,微软)。作为一个例子,火力地堡让他们的客户使用任何身份验证机制,只要你生成一个JWT与某些pre定义的属性,并与共享密钥签署调用他们的API。

Login page is not an special case: If you are using Protractor to write your functional tests, you don't need to handle any special case for login. Standard-based: your API could accepts a standard JSON Web Token (JWT). This is a standard and there are multiple backend libraries (.NET, Ruby, Java, Python, PHP) and companies backing their infrastructure (e.g. Firebase, Google, Microsoft). As an example, Firebase allows their customers to use any authentication mechanism, as long as you generate a JWT with certain pre-defined properties, and signed with the shared secret to call their API.

这篇关于在认证离子/科尔多瓦应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆