I have a new Box account. I created a new Box app from the developer console to process files stored in Box using a Python script. But the app_user_auth.authenticate_user() step is failing with below error
**BoxOAuthException**: Message: Please check the 'sub' claim. The 'sub' specified is invalid.
Status: 400
URL: https://api.box.com/oauth2/token
Method: POST
Sorry, I wasnt able to follow that. Is there a reason why you suggested me to look at “JWT without SDKs”? I had been trying to authenticate using “JWT with SDKs” all this while. Do you have any sample python script on how to read the folders in Box if I use “JWT without SDKs” for authentication?
I have same problem statement. My request fails with {‘error’: ‘invalid_grant’,
‘error_description’: "Please check the ‘sub’ claim. The ‘sub’ specified is "
‘invalid.’} My enterprise ID is zero.
In order to use applications with authentication types other than OAuth 2.0, you’d need to have a paid enterprise account. Free accounts do not have access to other authentication methods. We are working on launching our new free devleoper accounts in the near future.
From a python and Box SDK perspective, your code works flawlessly, so it must be permission, @smartoneinok is following up with you.
I just wanted to give you a tip relative to the construction of the JWTAuth.
You do not need to build it manually just to use an user.
If you need to authenticate a user from a JWTAuth object, you can re-use the settings, and just call the .authenticate_user(xyx) passing either a user_id or a User object.
Consider this sample:
""" Demo on using user identification on a JWT application"""
from typing import Union
from boxsdk import JWTAuth, Client
from boxsdk.object.user import User
USER_ID = "18622116055"
APP_USER_ID = "29599235430"
def get_client_user(user: [Union[str, "User"]]) -> Client:
"""Get client user"""
auth = JWTAuth.from_settings_file(".config.json")
auth.authenticate_user(user)
return Client(auth)
def get_client_enterprise() -> Client:
"""Get client enterprise"""
auth = JWTAuth.from_settings_file(".config.json")
# auth.authenticate_instance() # by default it authenticates the enterprise
return Client(auth)
def main():
client_enterprise = get_client_enterprise()
me = client_enterprise.user(user_id="me").get()
print(f"Service Account: {me.id} {me.name} {me.login}")
client_user = get_client_user(USER_ID)
me = client_user.user(user_id="me").get()
print(f"User Account: {me.id} {me.name} {me.login}")
app_user = client_enterprise.user(user_id=APP_USER_ID).get()
client_user_app = get_client_user(app_user)
me = client_user_app.user(user_id="me").get()
print(f"App User Account: {me.id} {me.name} {me.login}")
if __name__ == "__main__":
main()
Results in:
Service Account: 20344589936 UI-Elements-Sample AutomationUser_1841316_RbcnIM9B2l@boxdevedition.com
User Account: 18622116055 Rui Barbosa barduinor@gmail.com
App User Account: 29599235430 Test APP User AppUser_1841316_afcI7DCbFn@boxdevedition.com
Thank you for all the replies. The fix was simple. I shouldnt be using both Service account and app user to authenticate. The sample available in Git might have misled me.
Yes, We tried that yesterday but for some reason it didnt work. I created a new python environment and reinstalled the boxsdk library, after that service account client authentication worked just fine (but not mix of both authentications).