{"id":"6d7b7787a50a5021","repo":"tiangolo/fastapi","slug":"inactive-user-6d7b77","errorCode":null,"errorMessage":"Inactive user","messagePattern":"Inactive user","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"docs_src/security/tutorial005_py310.py","lineNumber":146,"sourceCode":"        raise credentials_exception\n    user = get_user(fake_users_db, username=token_data.username)\n    if user is None:\n        raise credentials_exception\n    for scope in security_scopes.scopes:\n        if scope not in token_data.scopes:\n            raise HTTPException(\n                status_code=status.HTTP_401_UNAUTHORIZED,\n                detail=\"Not enough permissions\",\n                headers={\"WWW-Authenticate\": authenticate_value},\n            )\n    return user\n\n\nasync def get_current_active_user(\n    current_user: User = Security(get_current_user, scopes=[\"me\"]),\n):\n    if current_user.disabled:\n        raise HTTPException(status_code=400, detail=\"Inactive user\")\n    return current_user\n\n\n@app.post(\"/token\")\nasync def login_for_access_token(\n    form_data: OAuth2PasswordRequestForm = Depends(),\n) -> Token:\n    user = authenticate_user(fake_users_db, form_data.username, form_data.password)\n    if not user:\n        raise HTTPException(status_code=400, detail=\"Incorrect username or password\")\n    access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)\n    access_token = create_access_token(\n        data={\"sub\": user.username, \"scope\": \" \".join(form_data.scopes)},\n        expires_delta=access_token_expires,\n    )\n    return Token(access_token=access_token, token_type=\"bearer\")\n\n","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/tiangolo/fastapi/blob/42a41db11f6882807ac3c057b942178d53b97438/docs_src/security/tutorial005_py310.py#L128-L164","documentation":"Default-parameter twin of error 55: `get_current_active_user` (`Security(get_current_user, scopes=['me'])`) raises HTTP 400 'Inactive user' when the resolved, scope-checked user has `disabled: True`. Sample user `alice` triggers it.","triggerScenarios":"`GET /users/me/` with a valid `me`-scoped JWT whose user is disabled.","commonSituations":"Disabled account with valid outstanding scoped JWT; flag not reset on reactivation.","solutions":["Authenticate as an active user (`johndoe`).","Set the user's `disabled` field to `False`.","Show a disabled-account message; do not retry."],"exampleFix":"# before\n# me-scoped token for disabled 'alice' => 400\n# after\n# me-scoped token for active 'johndoe' => 200","handlingStrategy":"try-catch","validationCode":"None","typeGuard":"def is_inactive(resp) -> bool:\n    return getattr(resp, 'status_code', None) == 400 and resp.json().get('detail') == 'Inactive user'","tryCatchPattern":"try:\n    me = client.get('/users/me/', headers=auth_header(token))\n    me.raise_for_status()\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code == 400 and e.response.json().get('detail') == 'Inactive user':\n        prompt_reactivation()\n    raise","preventionTips":["Do not retry 'Inactive user' on the same token.","Revoke scoped JWTs when disabling a user.","Keep the disabled flag in sync with admin tooling."],"tags":["authorization","security","jwt","user-management","fastapi"],"analyzedSha":"42a41db11f6882807ac3c057b942178d53b97438","analyzedAt":"2026-08-04T19:23:32.007Z","schemaVersion":2}