Question
JWT Oauth 2.0 using powershell
I am not sure if this is possible so I am looking for some help. I want to use the JWT token I received using the c# API in PowerShell scripts.
In this scenario I am successfully retrieving the AdminToken and saving it to a file with the following code:
BoxConfig config = null;
using (FileStream fs = new FileStream("BoxConfig.json", FileMode.Open))
{
config = BoxConfig.CreateFromJsonFile(fs);
}
// Create JWT auth using config file
var boxJWT = new BoxJWTAuth(config);
// Create admin client
var adminToken = boxJWT.AdminToken();
var adminClient = boxJWT.AdminClient(adminToken);
System.IO.File.WriteAllText("Token.txt", adminToken);
I then have a PowerShell cmdlet function that returns a BoxUser using the token as follows:
Get-BoxUser -Token 't8fUfbcHHcUbY8hak1o7UMEioSu0cOdy' -BoxUserid ***number removed for privacy*** -Verbose
That cmdlet returns this error:
User : System.Management.Automation.CmdletInvocationException: The remote server returned an error: (404) Not Found. ---> System.Net.WebException: The
server returned an error: (404) Not Found.
icrosoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
icrosoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
End of inner exception stack trace ---
ystem.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
ystem.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
ystem.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
ystem.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
:1 char:1
oxUser -Token '0UJWdo7g27ej1YTWWQO3nDtfLyI2Ls2p' -BoxUserid ***number removed for privacy*** -Verb ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
ullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-BoxUser
when I replace the -Token parameter with one that I receive using the Token Refresh method the
code works fine and the BoxUser is returned.
So something is different between token created using the Refresh method vs the JWT token.
Is what I am attempting even possible?
