You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug] Users cannot create their own API tokens #11486
Please verify that this bug has NOT been raised before.
I checked and didn't find a similar issue
Describe the bug*
Any non-admin user does not have the required API role permissions to generate their own API tokens. This prevents users from generating API tokens unless they have "admin" (role permissions).
Steps to Reproduce
Login using non-admin account (e.g. user: reader, pass: readonly)
Navigate to "User Settings" / "Security"
Select "Access Tokens" -> "Add Token"
Get "Permission Denied" error
Expected behaviour
Users should be able to control their own API tokens
Relevant Code
from ./src/backend/InvenTree/InvenTree/metadata.py:InvenTreeMetadata:determine_metadata (lines 133-140):
# Remove any HTTP methods that the user does not have permission forformethod, permissioninrolemap.items():
result=check_user_permission(user, self.model, permission) or (
role_requiredandcheck_user_role(user, role_required, permission)
)
ifmethodinactionsandnotresult:
delactions[method]
Note here that the users_apitoken model requires the RuleSetEnum.ADMIN role permission:
defget_ruleset_models() ->dict:
"""Return a dictionary of models associated with each ruleset. This function maps particular database models to each ruleset. """ruleset_models= {
RuleSetEnum.ADMIN: [
'auth_group',
'auth_user',
'auth_permission',
'users_apitoken',
...
It seems this reappeared with 1.7.0. At least the behavior is the same. Admin+Superuser can create tokens (The OPTIONS request returns GET in actions) while a normal user can't (actions is just an empty dictionary).
That's good to know, thank you! I'll do further tests in a fresh instance to rule out deployment issues. Can you point me at the piece of code that handles the OPTIONS request? I'm not familiar enough with DRF yet to understand this.
We ran into the same issue on 1.7.0. I am admin and could create an api token from the UI. my coworker who is no admin gets the same permission denied error.
Activity
SchrodingersGat commentedon Mar 11, 2026
@matmair any thoughts on how we best should handle this?
matmair commentedon Mar 11, 2026
I have to look into it but I think we have/had a permission overwrite that allowed the user to create a token for themself
matmair commentedon Mar 11, 2026
this looks like the wrong endpoint is called
SchrodingersGat commentedon Mar 11, 2026
Which endpoint should we be calling instead?
[bug] Users cannot create their own API tokens
matmair commentedon Mar 11, 2026
/user/token/ but there is also an issue in that; PR will follow
fix: low-privilege user token creation (#11492)
fix: low-privilege user token creation (inventree#11492)
fix: low-privilege user token creation (#11492) (#11521)
sur5r commentedon Nov 4, 2026
It seems this reappeared with 1.7.0. At least the behavior is the same. Admin+Superuser can create tokens (The
OPTIONSrequest returnsGETinactions) while a normal user can't (actionsis just an empty dictionary).Admin Superuser:
{ "name": "Get Auth Token", "description": "Return authentication token for an authenticated user.", "renders": [ "application/json" ], "parses": [ "application/json", "application/x-www-form-urlencoded", "multipart/form-data" ], "actions": { "GET": { "token": { "type": "string", "required": false, "read_only": true, "label": "Token", "allow_blank": false, "allow_null": false }, "name": { "type": "string", "required": true, "read_only": false, "label": "Token Name", "allow_blank": false, "allow_null": false, "help_text": "Custom token name", "max_length": 100 }, "expiry": { "type": "date", "required": false, "read_only": true, "label": "Expiry Date", "allow_null": false, "default": "2027-11-04", "help_text": "Token expiry date" }, "warning": { "type": "string", "required": false, "read_only": true, "label": "Warning", "allow_blank": false, "allow_null": false } } }, "model": "apitoken" }User:
{ "name": "Get Auth Token", "description": "Return authentication token for an authenticated user.", "renders": [ "application/json" ], "parses": [ "application/json", "application/x-www-form-urlencoded", "multipart/form-data" ], "actions": {}, "model": "apitoken" }matmair commentedon Nov 4, 2026
Against which endpoint? We had to do a lot of mfa security hardening; only the me/token/ subpath will issue tokens to non-staff users anymore
sur5r commentedon Nov 4, 2026
That was PUI against
/api/user/me/token.SchrodingersGat commentedon Nov 5, 2026
I have just been able to generate a new token for a non-staff, non-superuser account. We also have a regression test for this workflow in playwright.
@sur5r please run some more tests, and if you are certain there is an ongoing problem here, open a new issue.
sur5r commentedon Nov 5, 2026
That's good to know, thank you! I'll do further tests in a fresh instance to rule out deployment issues. Can you point me at the piece of code that handles the
OPTIONSrequest? I'm not familiar enough with DRF yet to understand this.SchrodingersGat commentedon Nov 5, 2026
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/InvenTree/metadata.py
HannesMorre commentedon Nov 16, 2026
We ran into the same issue on 1.7.0. I am admin and could create an api token from the UI. my coworker who is no admin gets the same permission denied error.
sur5r commentedon Nov 16, 2026
Workaround using manage.py shell: