# Get client original API address in a custom login action script

**URL:** <https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022>\
**Category:** Get Help\
**Tags:** ip, database-action-scri\
**Created:** [December 12, 2019, 1:37pm UTC](https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022 "2019-12-12T13:37:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![petriv.roma](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petriv.roma/32/14718_2.png) [@petriv.roma](https://community.auth0.com/u/petriv.roma)\
**Post date:** [December 12, 2019, 1:37pm UTC](https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022/1 "2019-12-12T13:37:07Z")

</div>

Hi, have a custom database connection with a custom login action script, like described here [https://auth0.com/docs/connections/database/custom-db/templates/login](https://auth0.com/docs/connections/database/custom-db/templates/login). I want to get user original IP address and send it to my BE. So then my backend knows what is the user client IP on login. Is it possible?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 12, 2019, 11:05pm UTC](https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022/3 "2019-12-12T23:05:18Z")

</div>

Hi @petriv.roma,

Welcome to the Auth0 Community Forum!

I found this from a previous support case:

> First off, assuming you are using the Universal Login Page, you could customize that page with some code to get the user’s IP/GeoIP information. For example: [jquery - How to get client's IP address using JavaScript? - Stack Overflow](https://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript).

> Next, once you have the IP details of the client, you could add this to the user’s metadata during the signup process. If you are using the Lock widget for login/signup, you would do that via a hidden [additional field](https://auth0.com/docs/libraries/lock/v11/configuration#additionalsignupfields-array-) (only applicable for database connections). For example…

```auto
additionalSignUpFields: [{
        type: "hidden",
        name: "ip",
        value: *<client-ip-obtained-from-above>*
      }]

```

Would that work for you?

---

<div class="post-metadata">

**Author:** ![petriv.roma](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petriv.roma/32/14718_2.png) [@petriv.roma](https://community.auth0.com/u/petriv.roma)\
**Post date:** [December 13, 2019, 1:02pm UTC](https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022/4 "2019-12-13T13:02:48Z")

</div>

Hi @dan.woda. Thanks for the reply. We are using a custom login page. But anyway we can’t rely on IP set from the FE side. I assume auth0 should know the real client IP since login request is processed on auth0 side. So I am looking for a way to send that real client IP to the BE. Is it possible somehow?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 13, 2019, 7:28pm UTC](https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022/5 "2019-12-13T19:28:24Z")

</div>

I see. I am not sure you will be able to get the IP info in your custom DB script. However, you should be able to get the IP data from a rule, which you could set up to either send a request to your BE with the data or you could use it directly in the rule to block authentication etc.

---

<div class="post-metadata">

**Author:** ![petriv.roma](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petriv.roma/32/14718_2.png) [@petriv.roma](https://community.auth0.com/u/petriv.roma)\
**Post date:** [December 15, 2019, 8:22pm UTC](https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022/6 "2019-12-15T20:22:53Z")

</div>

@dan.woda Is it possible to determine if request is a login request within a rule?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [December 20, 2019, 2:53pm UTC](https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022/7 "2019-12-20T14:53:03Z")

</div>

They will run on successful authentication. You can see some information about the authentication event via the [context object](https://auth0.com/docs/rules/references/context-object). I am not sure what you mean by determine if it is a login, as they should all be some sort of login.

What are you wanting to do with the IP data? You can whitelist or blacklist IPs using rules too if that is your end goal.

---

<div class="post-metadata">

**Author:** ![petriv.roma](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/petriv.roma/32/14718_2.png) [@petriv.roma](https://community.auth0.com/u/petriv.roma)\
**Post date:** [December 23, 2019, 9:48pm UTC](https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022/8 "2019-12-23T21:48:32Z")

</div>

I mean is there a way to run a rule only on log in? Because rules run on every authentication. Maybe it’s possible to determine if authentication is requested with `email/password` or something? IP data we need for an internal audit.

---

<div class="post-metadata">

**Author:** ![ashish](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ashish/32/7056_2.png) [@ashish](https://community.auth0.com/u/ashish)\
**Post date:** [December 23, 2019, 10:00pm UTC](https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022/9 "2019-12-23T22:00:28Z")

</div>

> [@petriv.roma](#):
>
> Maybe it’s possible to determine if authentication is requested with `email/password` or something?

You can look up `context.protocol` value for that. If it is `oauth2-resource-owner` then it is for database connection with email/pwd authentication. Please note that rules run on every _successful_ authentication and you don’t have access to anything else other than user email and password in your custom database login script.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [January 7, 2020, 2:00am UTC](https://community.auth0.com/t/get-client-original-api-address-in-a-custom-login-action-script/35022/10 "2020-01-07T02:00:31Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
