summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2026-03-17 16:15:41 -0400
committerGlenn Smith <glenn@vector35.com>2026-04-20 12:37:02 -0400
commit68f04aca3f4e04c1ec2c3b5d54c04ff05e9b0c58 (patch)
tree55f9128c8bcf02e1cf43c926ebd1fd4236b8aea1 /python
parentbfd306437f34ebc4d4170c5fb8170261585f6038 (diff)
Enterprise: Add AuthenticateWithToken api
For when you have a token and want to auth with it directly
Diffstat (limited to 'python')
-rw-r--r--python/enterprise.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/python/enterprise.py b/python/enterprise.py
index 4bc21d9b..b11be1dd 100644
--- a/python/enterprise.py
+++ b/python/enterprise.py
@@ -54,6 +54,19 @@ def is_connected() -> bool:
return core.BNIsEnterpriseServerConnected()
+def authenticate_with_token(token: str, remember: bool = True):
+ """
+ Authenticate to the server with an access token
+
+ :param str token: Token of auth session.
+ :param bool remember: Remember token in keychain
+ """
+ if not is_connected():
+ connect()
+ if not core.BNAuthenticateEnterpriseServerWithToken(token, remember):
+ raise RuntimeError(last_error())
+
+
def authenticate_with_credentials(username: str, password: str, remember: bool = True):
"""
Authenticate to the Enterprise Server with username/password credentials.
@@ -392,11 +405,20 @@ class LicenseCheckout:
except RuntimeError:
pass
+ if not got_auth and \
+ os.environ.get('BN_ENTERPRISE_TOKEN') is not None:
+ try:
+ authenticate_with_token(os.environ['BN_ENTERPRISE_TOKEN'])
+ got_auth = True
+ except RuntimeError:
+ pass
+
if not got_auth:
raise RuntimeError(
"Could not checkout a license: Not authenticated. Try one of the following: \n"
" - Log in and check out a license for an extended time\n"
" - Set BN_ENTERPRISE_USERNAME and BN_ENTERPRISE_PASSWORD environment variables\n"
+ " - Set BN_ENTERPRISE_TOKEN environment variable\n"
" - Use binaryninja.enterprise.authenticate_with_credentials or authenticate_with_method in your code"
)