boxsdk.exception.BoxOAuthException forJWT authorization Python
Im trying to get QAuth2.0 with Server JWT authorized to connect my app to Enterprise account in Box.
This is my code:
auth = JWTAuth(
client_id='*******************',
client_secret='*************************',
enterprise_id='*****',
jwt_key_id='********',
rsa_private_key_file_sys_path='/Users/*****/python_alert/private.pem',
rsa_private_key_passphrase='****',
store_tokens=None,
)
access_token = auth.authenticate_instance()
client = Client(auth)
This is the error I get:
No handlers could be found for logger "boxsdk.network.default_network"
Traceback (most recent call last):
File "box.py", line 33, in
access_token = auth.authenticate_instance()
File "/Library/Python/2.7/site-packages/boxsdk/auth/jwt_auth.py", line 384, in authenticate_instance
return self._auth_with_jwt(self._enterprise_id, 'enterprise')
File "/Library/Python/2.7/site-packages/boxsdk/auth/jwt_auth.py", line 243, in _auth_with_jwt
return self._construct_and_send_jwt_auth(sub, sub_type)
File "/Library/Python/2.7/site-packages/boxsdk/auth/jwt_auth.py", line 219, in _construct_and_send_jwt_auth
return self.send_token_request(data, access_token=None, expect_refresh_token=False)[0]
File "/Library/Python/2.7/site-packages/boxsdk/auth/oauth2.py", line 401, in send_token_request
token_response = self._execute_token_request(data, access_token, expect_refresh_token)
File "/Library/Python/2.7/site-packages/boxsdk/auth/oauth2.py", line 347, in _execute_token_request
six.raise_from(self._oauth_exception(box_api_excpetion.network_response, url), box_api_excpetion)
File "/Library/Python/2.7/site-packages/six.py", line 737, in raise_from
raise value
boxsdk.exception.BoxOAuthException:
Message: None
Status: 400
URL: https://api.box.com/oauth2/token
Method: POST
Headers: {'Content-Length': '145', 'Content-Encoding': 'gzip', 'Set-Cookie': 'box_visitor_id=5c1a9937dd6033.60743312; expires=Thu, 19-Dec-2019 19:17:11 GMT; Max-Age=31536000; path=/; domain=.box.com; secure, bv=OPS-42764; expires=Wed, 26-Dec-2018 19:17:11 GMT; Max-Age=604800; path=/; domain=.app.box.com; secure, cn=66; expires=Thu, 19-Dec-2019 19:17:11 GMT; Max-Age=31536000; path=/; domain=.app.box.com; secure, site_preference=desktop; path=/; domain=.box.com; secure', 'Age': '1', 'Strict-Transport-Security': 'max-age=31536000', 'Vary': 'Accept-Encoding', 'Connection': 'keep-alive', 'Cache-Control': 'no-store', 'Date': 'Wed, 19 Dec 2018 19:17:12 GMT', 'Content-Type': 'application/json'}
My enterprise admin has authorized my app as well. Can someone help please?
-
Hi all,
For anyone still experiencing this issue, it was discussed and solved (in one instance) in the Python SDK Github repo.
In short, here are some of the main reasons that this might be occurring:
Incorrect client ID / secret
Ensure that you are using the correct client ID and secret for the application. These can be found in the developer console by going to your app then clicking on the configuration section in the left hand nav.
Incorrectly formatted public key
The public key that you uploaded in the developer console is improperly formatted. The correct format looks like this:
-----BEGIN PUBLIC KEY----- //PUBLIC KEY INFO -----END PUBLIC KEY-----
Thanks all,
Jon
-
If you use the new JSON download option in your application setup, the JWTAuth code turns into:
with open( json_file_path ) as f:
lp = json.load( f )lp_s = lp[ 'boxAppSettings' ]
lp_s_a = lp_s[ 'appAuth' ]auth = boxsdk.JWTAuth(
enterprise_id = lp[ 'enterpriseID' ],client_id = lp_s[ 'clientID' ],
client_secret = lp_s[ 'clientSecret' ],
rsa_private_key_data = bytes( lp_s_a['privateKey'], 'ascii' ),
rsa_private_key_passphrase = bytes( lp_s_a[ 'passphrase' ], 'ascii' ),
jwt_key_id = lp_s_a[ 'publicKeyID' ]
)access_token = auth.authenticate_instance()
client = boxsdk.Client( auth ) -
I also got the same error. I used the SDK of JWT in Python and I am sure that my admin user has already approved my JWT application.
The code was:
auth = JWTAuth.from_settings_file('/Path_to_file/config.json') client = Client(auth) service_account = client.user().get() print('Service Account user ID is {0}'.format(service_account.id))
I used the 'Generate a Public/Private Keypair' in the Developer Console and downloaded the config_json file.The json file looks like:{ "boxAppSettings": { "clientID": "............................", "clientSecret": "..............................", "appAuth": { "publicKeyID": "xxxxx", "privateKey": "-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIIFXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXp\nXJA=\n-----END ENCRYPTED PRIVATE KEY-----\n", "passphrase": "XXXXXXXXXXXXXXXX" } }, "enterpriseID": "XXXXX"
But I got the same error message:boxsdk.exception.BoxOAuthException:
Message: A request parameter was invalid
Status: 400
URL: https://api.box.com/oauth2/token
Method: POSTCould someone help me with this error message? What should I change or deal with this problem? And How did you solve this issue?
Please sign in to leave a comment.
Comments
7 comments