3rd party Java Lib: ImportError

I would like to use a 3rd party Java Lib in scripting: GitHub - auth0/java-jwt: Java implementation of JSON Web Token (JWT)

I've found a jar file: Download java-jwt.jar - @com.auth0

and I've put it in the ignition/lib/core/common folder, gateway is restarted.
I'm trying to start testing functionality:
from com.auth0.jwt import *

But I get this error:
ImportError: No module named auth0

I know the proper way is to create an ignition module but we're not that familiar with java and never did such a thing so for now I just want to get something working and then look at a more permanent/better solution.

If you’re running this in the Designer script console you do also need to restart the Designer before it will load that JAR file.

Just restarted Gateway & Designer again but no change:

Hmm, this library has other transitive dependencies you probably haven't included in lib/core/common, so I bet it's failing to load somewhere.

How would I best go about troubleshooting this?
Ive added these:
Download jackson-core.jar - @com.fasterxml.jackson.core
Download jackson-databind.jar - @com.fasterxml.jackson.core

and rebooted gateway/designer and I'm still getting the same result.

If there's another JWT Lib that you know works would also be helpfull.
All I need is to verify a JWT, so validate signature and decode the base 64 to check scope and expiry

I might be able to do the same with a crypto and base 64 lib

In addition to the above, you should know that jython cannot use * in imports from java packages or classes. You must import specific classes.

It isn't a syntax error, but just doesn't yield anything.

I think you also need jackson-annotations-2.15.4.jar.

I just gave this a try and it worked for me :man_shrugging:

Added these 4 JAR files to lib/core/common, restarted Gateway, launched new Designer:

kevin@DV-55J5DY3-LT ~/D/m/t/dependency> ls -lh
total 2.3M
-rw-r--r--. 1 kevin kevin  74K Feb 15  2024 jackson-annotations-2.15.4.jar
-rw-r--r--. 1 kevin kevin 536K Feb 15  2024 jackson-core-2.15.4.jar
-rw-r--r--. 1 kevin kevin 1.6M Feb 15  2024 jackson-databind-2.15.4.jar
-rw-r--r--. 1 kevin kevin  63K Jan 29 06:39 java-jwt-4.5.0.jar

In the script console:

from com.auth0.jwt import JWT

JWT.decode("")

(which obviously errors out, but shows the library is loaded)

Java Traceback:
Traceback (most recent call last):
  File "<input>", line 3, in <module>
	at com.auth0.jwt.TokenUtils.wrongNumberOfParts(TokenUtils.java:45)
	at com.auth0.jwt.TokenUtils.splitToken(TokenUtils.java:23)
	at com.auth0.jwt.JWTDecoder.<init>(JWTDecoder.java:37)
	at com.auth0.jwt.JWTDecoder.<init>(JWTDecoder.java:33)
	at com.auth0.jwt.JWT.decode(JWT.java:52)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
com.auth0.jwt.exceptions.JWTDecodeException: com.auth0.jwt.exceptions.JWTDecodeException: The token was expected to have 3 parts, but got 0.

	at org.python.core.Py.JavaError(Py.java:545)
	at org.python.core.Py.JavaError(Py.java:536)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:208)
	at org.python.core.PyObject.__call__(PyObject.java:461)
	at org.python.core.PyObject.__call__(PyObject.java:465)
	at org.python.pycode._pyx11.f$0(<input>:3)
	at org.python.pycode._pyx11.call_function(<input>)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1703)
	at org.python.core.Py.exec(Py.java:1747)
	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)
	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)
	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:628)
	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:616)
	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: com.auth0.jwt.exceptions.JWTDecodeException: The token was expected to have 3 parts, but got 0.
	at com.auth0.jwt.TokenUtils.wrongNumberOfParts(TokenUtils.java:45)
	at com.auth0.jwt.TokenUtils.splitToken(TokenUtils.java:23)
	at com.auth0.jwt.JWTDecoder.<init>(JWTDecoder.java:37)
	at com.auth0.jwt.JWTDecoder.<init>(JWTDecoder.java:33)
	at com.auth0.jwt.JWT.decode(JWT.java:52)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
	... 19 more
Traceback (most recent call last):
  File "<input>", line 3, in <module>
	at com.auth0.jwt.TokenUtils.wrongNumberOfParts(TokenUtils.java:45)
	at com.auth0.jwt.TokenUtils.splitToken(TokenUtils.java:23)
	at com.auth0.jwt.JWTDecoder.<init>(JWTDecoder.java:37)
	at com.auth0.jwt.JWTDecoder.<init>(JWTDecoder.java:33)
	at com.auth0.jwt.JWT.decode(JWT.java:52)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
com.auth0.jwt.exceptions.JWTDecodeException: com.auth0.jwt.exceptions.JWTDecodeException: The token was expected to have 3 parts, but got 0.
>>> 

Great! thx.
This also works on my end.

Just keep in mind you'll have to repeat this procedure any time you upgrade Ignition. These lib/core/* directories are wiped out and replaced during the upgrade.

Thanks for the headsup.
When life is less busy we'll look into creating a .modl

or even better, ignition just implements JWT verify and JWT decode :smiley: