box / box-windows-sdk-v2

Windows SDK for v2 of the Box API. The SDK is built upon .NET Framework 4.5

Home Page:https://developer.box.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.<

$>d__0.MoveNext() in C:\Users\SatheeshAvula\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 20

box-sdk-1 (1)

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'm using the nuget library, not the git hub code; how can I get the assertion? please advise

image

I managed to debug it by following these steps:

I cloned this repo, removed Nuget, and added a.net project reference. That's it; I'm able to debug it.

I copied the hash to that given url and, after that, decoded the header section, alg: "none."

How can we set this alg in dotnet projects?

image

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

_credentials = new SigningCredentials(new RsaSecurityKey(rsa), SecurityAlgorithms.RsaSha256);
. Can you check what is returned by SecurityAlgorithms.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)

image

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?

commented

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.

commented

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.