移动AngularJS应用程序上的用户身份验证 [英] User Authentication on a mobile AngularJS App

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

问题描述

我想问一个问题,这可能会有多个解决方案,但在这个阶段我不知道如何解决这个问题。

I'd like to ask a question, which will likely have more than one solution but at this stage I don't know how to solve this problem.

我目前正在构建一个内置Angular / Ionic的移动应用程序,该应用程序正在访问Woocommerce API,应用程序需要传递消费者密钥以及秘密才能获取产品信息以及创建产品。

I'm currently building a mobile application built in Angular/Ionic which is accessing the Woocommerce API, for which the app needs to pass a consumer key as well as secret in order to obtain product information as well as create products.

我认为我无法直接访问手机上的数据库,我可以存储这些详细信息以验证我的应用并将其指向正确的woocommerce商店。

I assume that I do not have direct access to a database on my phone where I can store theses details to authenticate my app and point it at the right woocommerce store.

即使我将这些存储在基于服务器的应用程序中,我的移动应用程序仍然需要对基于服务器的应用程序进行身份验证才能访问正确的woocommerce商店。

Even if I store these in a server based app, then my mobile app still needs to authenticate to the server based app in order to access the correct woocommerce store.

有人可以指出开发人员如何解决这个问题的正确方向吗?

Could somebody point me into the right directions as to how developers go about this problem?

推荐答案

通常,Phonegap / Ionic中的移动身份验证看起来像这样:

Usually, mobile authentication in Phonegap/Ionic looks like that:


  1. 您使用Login / Pass或ApiKey发送身份验证请求。

  2. 服务器响应一些令牌。

  3. 您将令牌存储在localStorage中。

  4. 每次ApiRequest发送令牌。

  1. You send Authentication request with Login/Pass or ApiKey.
  2. Server response some Token.
  3. You store Token in localStorage.
  4. Send token with every ApiRequest.

以下是如果您已经有一些令牌,如何将令牌传递给每个API请求的示例。

Here is example how pass token to every API request if you already have some token.

angular.module('app').config(AppConfig);
AppConfig.$inject = ['$httpProvider'];
function AppConfig($httpProvider, $sceProvider) {  
    var token = simpleStorage.get('access_token'); // simpleStorage here is a js-plugin for using LocalStorage
    if(token){
        $httpProvider.defaults.headers.common['access-token'] = token;
    }
}

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

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