The API returned an error [BadRequest] invalid_grant - Algorithm not allowed
satsnyder opened this issue · comments
DOTNET NameSpace we used :
using Box.V2;
using Box.V2.Config;
using Box.V2.JWTAuth;
using Box.V2.Models;
.NET SDK Package Version :
TimeZone of machine where this programming running"
--------------------
time zone : IST
TimeStamp : 22/12/2022 2:02AM IST
Code Details:
--------------------
string path = "C:\Sps\boxconfig\969190330__config1.json";
FileStream jsonConfig = new FileStream(path, FileMode.Open);
var config = BoxConfigBuilder.CreateFromJsonFile(jsonConfig).Build();
var session = new BoxJWTAuth(config);
var token = await session.AdminTokenAsync();
BoxClient client = session.AdminClient(token);
Error Details:
------------------
Box.V2.Exceptions.BoxAPIException
HResult=0x80131500
Message=The API returned an error [BadRequest] invalid_grant - Algorithm not allowed
Source=Box.V2.Core
StackTrace:
at Box.V2.JWTAuth.BoxJWTAuth.d__14.MoveNext()
at Box.V2.JWTAuth.BoxJWTAuth.d__12.MoveNext()
at Program.<
Box Support Follow up links:
------------------
https://support.box.com/hc/en-us/requests/2758979
Hi @satsnyder,
the error message says that the JWT assertion we are sending has not allowed algorithm type - so let's check it. Can you copy the value of the variable assetion
during authentication process, which is available here and then paste it to JWT decoder, e.g. https://jwt.io/ . In the header there should be an entry with: "alg": "RS256"
. Let me know if you have the same algorithm there.
Best,
@lukaszsocha2
I should be set by .NET Box SDK, but maybe you don't have all required dependencies. The algorithm is supposed to be set in this line
. Can you check what is returned bySecurityAlgorithms.RsaSha256
?It's not even entering there, as if condition is not satisfied, the box configuration's JWTPrivateKey and JWTPrivateKeyPassword are empty. For your information, I'm using the RSA key to authenticate, not the JWT( I mean i configured my RSA Key in BOX and downloaded the config and using that config JSON)
In your JWT config file, which you downloaded from Box Developer Console, do you have any value set to privateKey
or the value is empty ?
I assume it is empty then you should:
- paste your private key and passphrase there
or - Generate a Public/Private Keypair in Developer Console. The new config file will be downloaded automatically. Use this config file as it is already filled with private key - there is no need to do anything manually. This is recommended way.
Yeah, its empty, i already configured the public key, still the private key is not showing its empty always
Can you remove all existing Public Keys and Generate a new one using Box Developer Console. Generate a Public/Private Keypair
should cause downloading new config with all required values.
Hi @satsnyder,
I just wanted to confirm if the solution proposed by Łukasz resolved your problem?
This issue has been automatically marked as stale because it has not been updated in the last 30 days. It will be closed if no further activity occurs within the next 7 days. Feel free to reach out or mention Box SDK team member for further help and resources if they are needed.
This issue has been automatically closed due to maximum period of being stale. Thank you for your contribution to Box .NET SDK and feel free to open another PR/issue at any time.