Ionic/Cordova 应用程序中的身份验证 [英] Authentication in Ionic/Cordova App

查看:26
本文介绍了Ionic/Cordova 应用程序中的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我不是专业人士.

First off, I'm no pro.

为了成为更好的开发人员,我试图了解需要什么以及如何完成为 Ionic-Framework 应用程序创建注册/登录.

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,所以我猜我可能会遇到一些 COR 问题.

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.

我了解 Ionic-Framework 使用状态和基于 angular-client-side-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 服务器 - 感谢 DigitalOcean(我应该使用它作为我的数据库的代理吗?)
  • CouchDB 服务器(我们来了全栈)

我的问题:

  1. 使用混合应用时进行身份验证的标准方法是什么?
  2. 我应该使用 Node.JS 作为数据库的代理吗?
  3. 我应该跳过 node.js 并直接使用 CouchDB 服务器进行身份验证吗?(我听说过)
  4. 我这样做是不是完全错误?
  5. 我的潜在障碍是什么?
  6. CORS 如何处理混合应用程序?
  7. 有什么我遗漏的吗?

感谢您帮助我成为更好的开发者.

Thanks for helping me become a better developer.

推荐答案

nathvarun 给出了一个非常完整的答案,但我想分享我在我的应用中进行身份验证的步骤.

nathvarun gave a very complete answer, but I'd like to share the steps I do for authentication in my app.

  1. 通过ajax向服务器发送email + password
  2. 在服务器中生成一个token并将其发送回应用
  3. localStorage
  4. 中存储email + token
  5. 对于我向服务器发出的每个请求,我都会通过 POST
  6. 发送 email + token
  7. 在服务器中,我使用该令牌验证该用户的真实性,如果 true 执行该方法,如果 false 我将错误发送回应用程序 (401)
  8. 如果应用程序收到成功,那么没关系,如果收到错误,我将重定向到登录屏幕.
  1. Send email + password via ajax to the server
  2. Generate a token in the server and send it back to the app
  3. Store email + token in localStorage
  4. For every single request I make to the server I send email + token via POST
  5. In the server I verify authenticity of that user with that token, if true the method is executed, if false I send back to the app an error (401)
  6. If app receives success, then it's ok, if receives error I redirect to login screen.

好消息是,当应用程序打开时,您可以从 localStorage 获取 email + token,发送到服务器,如果该令牌对该用户没问题,重定向到主屏幕,否则重定向到登录.然后每当用户清除应用程序的缓存时,他就会被重定向到登录屏幕.

Nice thing is that when the app is open, you can get the email + token from localStorage, send to the server, if that token is ok for that user, redirect to main screen, otherwise redirect to login. Then whenever user clears the cache of the app, he is redirected to login screen.

这篇关于Ionic/Cordova 应用程序中的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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