维护REST API在防爆preSS密钥和访问令牌和智威汤逊的NodeJS与Facebook [英] Maintaining Secret key and Access Token for JWT in Express and NodeJS with Facebook in Rest API

查看:303
本文介绍了维护REST API在防爆preSS密钥和访问令牌和智威汤逊的NodeJS与Facebook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序:


  • 服务器(REST API服务器)

    • 节点JS

    • 防爆preSS

    • jsonwebtokens

    • 前preSS-智威汤逊

    • 猫鼬


    • 引导

    • 角JS

    • 本地存储

    • 角的Facebook

    • 角智威汤逊

    Lateron,客户端应用程序将被移植为Android,iPhone和使用PhoneGap的其他平台。如果是OAuth,我使用Facebook的作为供应商。现在,我才意识到JSON网络令牌是去为这种设置方式。我的问题是一个建筑的一个相当不是语法一 - ?如何签约的NodeJS facebook的访问令牌和用户ID与智威汤逊,当管理密钥

    Lateron, the client app will be ported for android, iphone and other platforms using phonegap. For OAuth, I am using Facebook as the provider. Now, I just realized JSON Web Tokens are the way to go for this kind of set up. My question is an architectural one rather than syntactical one - how to manage a secret key when signing the facebook access token and user id with JWT in nodejs?

    因此​​,这是流在我的应用程序是如何工作的:

    So this is how the flow works in my app:


    1. 客户端有一个登录按钮

    2. 用户点击该按钮> Facebook的身份验证启动

    3. 客户端接收user_id说明和FB访问令牌

    4. 客户端发[ POST JSON身体的]既USER_ID并访问令牌为节点+防爆preSS服务器 http://server.com/auth/login

    5. 节点服务器已申请前preSS-智威汤逊,除了的 /认证/登录的所有路由使用

    1. Angular client has a Login button
    2. User Clicks the button > Facebook Auth starts
    3. Client receives user_id and FB Access Token
    4. Client sends[POST json body] both user_id and Access Token to Node+Express Server at 'http://server.com/auth/login'
    5. Node Server has applied express-jwt to all routes except /auth/login with a

    VAR前pressJwt =要求('前preSS-智威汤逊');

    var expressJwt = require('express-jwt');

    VAR智威汤逊=要求('jsonwebtoken');

    var jwt = require('jsonwebtoken');

    app.use(如pressjwt({秘密:''} {:[/认证/登录']),除非(路径}。'));

    app.use(expressjwt({ secret: ''}).unless({path: ['/auth/login']}));

    节点服务器从接收数据的 req.body ,获取来自Facebook使用JavascriptSDK的所有配置文件的详细信息,而且它使用的迹象

    Node server receives data from req.body, fetches all profile details from facebook using the JavascriptSDK, and signs it using

    VAR令牌=前pressjwt.sign({}的个人资料,);

    var token=expressjwt.sign({profile}, );

    现在,我的问题是:


    1. 请我真的需要存储在数据库中的JWT令牌?我当然不是在请求头与数据库进行比较令牌
    2. 请我需要生成一个人的日志中随机密钥安全,每一次?如果是的话那么如何将这项适合在客户端和服务器?

    3. 何时何地,我需要检查令牌过期?和我怎么刷新?

    我有点失去了对设计流程和机制。

    I am kind of lost about the design flow and mechanism.

    推荐答案

    广告1.您不必在智威汤逊存储在数据库中。用户ID可以是有效载荷的一部分,因此没有必要吧。

    Ad 1. You do not have to store the JWT in the database. User ID can be part of the payload, therefore there's no need for it.

    广告2.它是服务器端应用程序使用一个密钥生成所有JWT的普遍做法。

    Ad 2. It's a common practice for the server side app to use one secret key for generating all JWT.

    广告3.检查令牌在每次请求你的API过期,禁止访问如果令牌已过期,则返回401状态code。客户端应用程序应提示用户凭据,并要求新智威汤逊。如果你想避免用户重新提交的证书,你可以发出以后可以用来产生新的智威汤逊刷新令牌。

    Ad 3. Check if token has expired on each request to your API and disallow access if the token has expired, return 401 status code. Client app should prompt user for credentials and request new JWT. If you want to avoid users re-submitting the credentials you can issue a refresh token that later can be used to generate new JWT.

    智威汤逊刷新标记流程

    <一个href=\"http://bitoftech.net/2014/07/16/enable-oauth-refresh-tokens-angularjs-app-using-asp-net-web-api-2-owin/\">http://bitoftech.net/2014/07/16/enable-oauth-refresh-tokens-angularjs-app-using-asp-net-web-api-2-owin/

    这篇关于维护REST API在防爆preSS密钥和访问令牌和智威汤逊的NodeJS与Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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