Web Connection
DoorDash JWT
Hi Rick,
How would I do this in WebConnect to create the JWT token?
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
var accessKey = new Dictionary<string, string>{
{"developer_id", "PLACEHOLDER"},
{"key_id", "PLACEHOLDER"},
{"signing_secret", "PLACEHOLDER"}
};
var decodedSecret = Base64UrlEncoder.DecodeBytes(accessKey["signing_secret"]);
var securityKey = new SymmetricSecurityKey(decodedSecret);
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
var header = new JwtHeader(credentials);
header["dd-ver"] = "DD-JWT-V1";
var payload = new JwtPayload(
issuer: accessKey["developer_id"],
audience: "doordash",
claims: new List<Claim> { new Claim("kid", accessKey["key_id"]) },
notBefore: null,
expires: System.DateTime.UtcNow.AddSeconds(60),
issuedAt: System.DateTime.UtcNow);
var securityToken = new JwtSecurityToken(header, payload);
var token = new JwtSecurityTokenHandler().WriteToken(securityToken);
Console.WriteLine(token);
Can you point me in the right direction?
Thanks, Joy
I would create a .NET component and call it from FoxPro with wwDotnetBridge. Creating that code in FoxPro with wwDotnetBridge
would be very tedious and some stuff may not work due to the various collection assignments. Easier to do in .NET and call from FoxPro instead IMHO.
+++ Rick ---
HI Rick,
I got a C# to create the token. How do I post this?
I tried this
lctoken = FILETOSTR('abc.txt')
lcAuthToken2 = STRCONV(lctoken, 13)
SET PROCEDURE TO wwhttp ADDITIVE
set procedure to wwutils additive
set procedure to json additive
loHTTP=CREATEOBJECT("wwHttp")
lchtml = ''
loHTTP.Addpostkey(lcJson)
*** With a login and SSL and POSTing data to the server
loHttp.AddHeader("Authorization","Bearer " + lcAuthToken2)
loHttp.cContentType = "application/json"
lcHTML = loHTTP.HTTPGet("https://openapi.doordash.com/drive/v2/deliveries'")
I got an error, but I want you to tell me if the AddHeader part for the JWT token is correct or not.
Thanks, Joy