fusionauth-typescript-client icon indicating copy to clipboard operation
fusionauth-typescript-client copied to clipboard

actionUser `expiry` field cannot be set to "infinity" (9223372036854775807)

Open ceefour opened this issue 4 years ago • 4 comments

Reference: https://fusionauth.io/docs/v1/tech/apis/actioning-users/#take-an-action-on-a-user

To cause the action to be applied indefinitely, or until the action is canceled or modified, set this value to 9223372036854775807.

Since Java API uses Long and the expiry field TypeScript definition uses number, trying to use that number literal will give TypeScript warning "Numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as integers.ts(80008)"

And also when executing the result is:

Invalid JSON in the request body. The property was [action.expiry]. The error was [Possible conversion error]. The detailed exception was [Numeric value (9223372036854776000) out of range of long (-9223372036854775808 - 9223372036854775807)
 at [Source: (org.apache.catalina.connector.CoyoteInputStream); line: 1, column: 181] (through reference chain: io.fusionauth.domain.api.user.ActionRequest["action"]->io.fusionauth.domain.api.user.ActionRequest$ActionData["expiry"])].

Workaround

Use: '9223372036854775807' as any

Proposed Solution

If possible, change the type to number | string | undefined which is probably a good-enough compromise retaining backwards compatibility.

If not possible, then string | undefined is more flexible.

ceefour avatar Feb 06 '21 13:02 ceefour

It looks like you might have a typo. The docs state that the max value is 9223372036854775807 but the error you've included says you passed in the value 9223372036854776000. I believe the documentation is correct and as long as the client library passes the value as a JSON number, it should work.

Let me know if I'm missing something on this issue though.

voidmain avatar Feb 08 '21 16:02 voidmain

It looks like you might have a typo. The docs state that the max value is 9223372036854775807 but the error you've included says you passed in the value 9223372036854776000. I believe the documentation is correct and as long as the client library passes the value as a JSON number, it should work.

It is easy to check this by using your own local node or your browser's Inspect:

image

That's really the JavaScript/TypeScript problem mentioned there: (this is unique to JS platform and not a problem with Java, Python, etc.)

Numeric literals with absolute values equal to 2^53 or greater are **too large to be represented accurately as integers.**ts(80008)

ceefour avatar Feb 08 '21 17:02 ceefour

Ah. Got it now. That's quite the limitation of the JS system and it makes no sense that the system would be rounding UP. That's just crazy talk.

Honestly, I've never been a huge fan of using Long.MAX_VALUE for Infinite actions. I'd prefer to update the FusionAuth code to handle nulls and missing values for expiry.

I did a quick review of the code and it appears that using a value such as 9223372036854775000 should work. The event will contain the duration field, but the rest of the code will function properly.

voidmain avatar Feb 09 '21 15:02 voidmain

@voidmain I do agree that expiry == null should mean infinite. But definitely null never means 0 here, as an expiry of 0 don't make sense.

It's still practical to follow your suggestion of a large-enough instant, as for all practical reasons the user would've already been dead anyway by the time his/her user account restriction is lifted. ^_^ (unless his grand-grand-grand-grand-grandchildren cares enough to continue the trolling, hehe)

Update: I just found out the max instant is the year 1000000000. So that's a lot of grandchildren to pass the FusionAuth user account to. ;-) (it'd be cool if someone still uses FusionAuth by then ^_^)

ceefour avatar Feb 10 '21 11:02 ceefour