使用条带订阅Node.js进行身份验证

使用条带订阅Node.js进行身份验证,node.js,mongodb,mongoose,jwt,stripe-payments,Node.js,Mongodb,Mongoose,Jwt,Stripe Payments,我无法确定使用条带攻击订阅身份验证的最佳方法。我有一个预先存在的MERN堆栈,它使用JWT进行身份验证,存储订阅id。但是,为了检测诸如取消、发票不完整等更改,我想不出没有套接字的解决方案 有什么想法吗?在续订JWT之前,只需检查订阅的状态,并确保到期时间足够短,以确保您在无报酬访问窗口方面感到舒适 您还可以使用一些中间件,对每个ajax请求(或至少是常见/频繁的ajax请求)执行此操作,如果订阅不再被视为“付费”,则返回402并使JWT无效。在续订JWT之前,只需检查订阅的状态,并确保到期时间

我无法确定使用条带攻击订阅身份验证的最佳方法。我有一个预先存在的MERN堆栈,它使用JWT进行身份验证,存储订阅id。但是,为了检测诸如取消、发票不完整等更改,我想不出没有套接字的解决方案


有什么想法吗?

在续订JWT之前,只需检查订阅的状态,并确保到期时间足够短,以确保您在无报酬访问窗口方面感到舒适


您还可以使用一些中间件,对每个ajax请求(或至少是常见/频繁的ajax请求)执行此操作,如果订阅不再被视为“付费”,则返回402并使JWT无效。

在续订JWT之前,只需检查订阅的状态,并确保到期时间足够短,以使您在无报酬访问窗口方面感到舒适


您还可以使用一些中间件来为每个ajax请求(或者至少是一个常见/频繁的ajax请求)执行此操作,如果订阅不再被认为是“付费”的,则该中间件将返回402并使JWT无效。

看看用于接收事件通知的条带Webhook

监听条带帐户上的事件,以便您的集成可以自动触发反应

Stripe使用Webhook在帐户中发生事件时通知应用程序。Webhook对于异步事件特别有用,例如当客户的银行确认付款、客户对费用提出异议或定期付款成功时

只需三个步骤即可开始使用Webhook与条带集成:

1.在服务器上创建webhook端点

2.使用Stripe CLI测试端点是否正常工作

3.使用条带注册端点以启用

创建webhook的基本示例

// This example uses Express to receive webhooks
const app = require('express')();

// Use body-parser to retrieve the raw body as a buffer
const bodyParser = require('body-parser');

// Match the raw body to content type application/json
app.post('/webhook', bodyParser.raw({type: 'application/json'}), (request, response) => {
  let event;

  try {
    event = JSON.parse(request.body);
  } catch (err) {
    response.status(400).send(`Webhook Error: ${err.message}`);
  }

  // Handle the event
  switch (event.type) {
    case 'payment_intent.succeeded':
      const paymentIntent = event.data.object;
      // Then define and call a method to handle the successful payment intent.
      // handlePaymentIntentSucceeded(paymentIntent);
      break;
    case 'payment_method.attached':
      const paymentMethod = event.data.object;
      // Then define and call a method to handle the successful attachment of a PaymentMethod.
      // handlePaymentMethodAttached(paymentMethod);
      break;
    // ... handle other event types
    default:
      // Unexpected event type
      return response.status(400).end();
  }

  // Return a response to acknowledge receipt of the event
  response.json({received: true});
});

app.listen(8000, () => console.log('Running on port 8000'));

看看用于接收事件通知的stripewebhook

监听条带帐户上的事件,以便您的集成可以自动触发反应

Stripe使用Webhook在帐户中发生事件时通知应用程序。Webhook对于异步事件特别有用,例如当客户的银行确认付款、客户对费用提出异议或定期付款成功时

只需三个步骤即可开始使用Webhook与条带集成:

1.在服务器上创建webhook端点

2.使用Stripe CLI测试端点是否正常工作

3.使用条带注册端点以启用

创建webhook的基本示例

// This example uses Express to receive webhooks
const app = require('express')();

// Use body-parser to retrieve the raw body as a buffer
const bodyParser = require('body-parser');

// Match the raw body to content type application/json
app.post('/webhook', bodyParser.raw({type: 'application/json'}), (request, response) => {
  let event;

  try {
    event = JSON.parse(request.body);
  } catch (err) {
    response.status(400).send(`Webhook Error: ${err.message}`);
  }

  // Handle the event
  switch (event.type) {
    case 'payment_intent.succeeded':
      const paymentIntent = event.data.object;
      // Then define and call a method to handle the successful payment intent.
      // handlePaymentIntentSucceeded(paymentIntent);
      break;
    case 'payment_method.attached':
      const paymentMethod = event.data.object;
      // Then define and call a method to handle the successful attachment of a PaymentMethod.
      // handlePaymentMethodAttached(paymentMethod);
      break;
    // ... handle other event types
    default:
      // Unexpected event type
      return response.status(400).end();
  }

  // Return a response to acknowledge receipt of the event
  response.json({received: true});
});

app.listen(8000, () => console.log('Running on port 8000'));

是的,就数据库更改而言,我计划使用web钩子。我更倾向于在不使用web套接字的情况下刷新客户端的凭据,如果这样做有意义的话。感谢您的回复啊,我正计划利用web钩子来更改数据库。我更倾向于在不使用web套接字的情况下刷新客户端的凭据,如果这样做有意义的话。感谢您的回复啊,所以我的想法是每5分钟(从JWT到期)重新加载一次用户模式,并比较那里的状态以确定是否存在争议(如果有效),同时发送一个刷新的用户对象。或者将常规身份验证和订阅保存在单独或嵌入的令牌中。我唯一关心的是在通用身份验证令牌上有如此短的到期时间,即验证token@NicholasDullam这对你来说可能是一篇有用的文章:是的,所以我的想法是重新加载用户模式,例如,每5分钟(从JWT到期)一次,并比较那里的状态是否存在争议(如果有效),发送刷新的用户对象。或者将常规身份验证和订阅保存在单独或嵌入的令牌中。我唯一关心的是在通用身份验证令牌上有如此短的到期时间,即验证token@NicholasDullam这可能是一篇对您有用的文章: