Skip to content

Users lack permission to create API tokens for themselves #13299

Closed

Description

@sur5r

Please verify that this bug has NOT been raised before.

  • I checked and didn't find a similar issue

Describe the bug*

This is a followup to #11486.

I'm unable to create an API token as a non-superuser.

I followed the code flow and ended up doing

inventree=> select * from auth_permission where id=280;
 id  |        name        | content_type_id |   codename    
-----+--------------------+-----------------+---------------
 280 | Can view API Token |              70 | view_apitoken

inventree => insert into auth_user_user_permissions values(default,3,280);
INSERT 0 1

Afterwards, I was able to create and revoke API tokens for my user.

I've tested this on both 1.7.2 and current master (1f51dfe) and the behavior is the same.

Steps to Reproduce

  1. Go to User settings
  2. Go to Security
  3. Go to Access Tokens
  4. Click on "+"
  5. Observe error message

Expected behaviour

  1. Go to User settings
  2. Go to Security
  3. Go to Access Tokens
  4. Click on "+"
  5. Enter token name
  6. Have a new token

Deployment Method

Bare metal

Version Information

InvenTree-Version: 1.7.2
Django Version: 5.2.17
Commit Hash: 7a137c8
Commit Date: 2026-11-13
Commit Branch: stable
Database: null
Debug-Mode: False
Deployed using Docker: False
Platform: null
Installer:
Active plugins: false

Try to reproduce on the demo site

I tried to reproduce

Is the bug reproducible on the demo site?

Not reproducible

Relevant log output

I have reviewed this report for correctness and filled out all sections.

  • I have checked this report. I acknowledge that filing bugs via AI agents without review might lead to being blocked.

Activity

  1. added theissue type on Nov 16, 2026
  2. added
    bug
    question
    triage:not-checked
    on Nov 16, 2026
  3. sur5r commented on Nov 16, 2026

    @sur5r
    ContributorAuthor

    Workaround using manage.py shell:

    from django.contrib.auth.models import Permission,User
    u=User.objects.get(username='sur5r')
    p=Permission.objects.get(content_type__model="apitoken",codename="view_apitoken")
    u.user_permissions.add(p)
    u.save()
  4. sur5r commented on Nov 16, 2026

    @sur5r
    ContributorAuthor

    Another thing I noticed: Revoking a token is done using the DELETE verb. It works despite the permission check for it returning false and thus DELETE not being part of actions. Seems inconsistent to me.

  5. SchrodingersGat commented on Nov 17, 2026

    @SchrodingersGat
    Member

    @sur5r thanks for reporting - fix is incoming in #13307

  6. removed
    question
    triage:not-checked
    on Nov 17, 2026
  7. added this to the 1.8.0 milestone on Nov 17, 2026
  8. sur5r commented on Nov 17, 2026

    @sur5r
    ContributorAuthor

    Thank you very much. I still don't understand why it worked on the demo site, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions