【问题标题】:How to send the IP Address of a visitor along in Auth0?如何在 Auth0 中发送访问者的 IP 地址?
【发布时间】:2017-11-28 15:44:40
【问题描述】:

我在后端使用auth0 作为注册/登录系统的一部分,到目前为止一切正常。

但我注意到所有用户的帐户显然都位于爱尔兰(这是我的服务器所在的地方)。

我已经确定这个问题是因为它是我的服务器发送请求而不是前端。

因此,我想知道是否有办法将访问者的 Remote IP 与对 Auth0 的调用一起传递?

【问题讨论】:

  • 根据文档,api似乎没有提供这个功能。
  • 这就是我的猜测,我将尝试发送带有 X-Forwarded-For 标头的请求,也许这会起作用:]
  • 对于任何寻找后续行动的人,我也在 auth0 论坛上问过这个问题。 auth0.com/forum/t/no-way-to-set-ip-address-to-real-ip/5206/3

标签: auth0


【解决方案1】:

如果您使用密码授权,您可以将auth0-forwarded-for 标头(类似于x-forwarded-for)与请求一起发送。此 IP 将用于暴力检测等。

更多信息在这里:https://auth0.com/docs/api-auth/tutorials/using-resource-owner-password-from-server-side#sending-the-end-user-ip-from-your-server

【讨论】:

    【解决方案2】:

    作为示例,您可以使用如下所示的内容

    var request = require("request");
    
    app.post('/api/auth', function(req, res, next) {
      var options = {
        method: 'POST',
        url: 'https://YOUR_AUTH0_DOMAIN/oauth/token',
        headers: {
          'content-type': 'application/json',
          'auth0-forwarded-for': req.ip // End user ip
        },
        body: {
          grant_type: 'password',
          username: 'USERNAME',
          password: 'PASSWORD',
          audience: 'API_IDENTIFIER',
          scope: 'SCOPE',
          client_id: 'YOUR_CLIENT_ID',
          client_secret: 'YOUR_CLIENT_SECRET' // Client is authenticated
        },
        json: true
      };
    
      request(options, function (error, response, body) {
        if (error) return next(error);
    
        // ...
      });
    });
    

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 1970-01-01
      • 2011-12-17
      • 2018-11-17
      • 2020-12-12
      • 2023-04-11
      • 1970-01-01
      • 2012-04-23
      • 2021-01-20
      相关资源
      最近更新 更多