Web Connection
DoorDash JWT
Gravatar is a globally recognized avatar based on your email address. DoorDash JWT
  Joy Tan
  All
  Sep 2, 2022 @ 05:22pm

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

Gravatar is a globally recognized avatar based on your email address. re: DoorDash JWT
  Rick Strahl
  Joy Tan
  Sep 2, 2022 @ 06:01pm

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

Gravatar is a globally recognized avatar based on your email address. re: DoorDash JWT
  Joy Tan
  Rick Strahl
  Sep 2, 2022 @ 07:19pm

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

Gravatar is a globally recognized avatar based on your email address. re: DoorDash JWT
  Joy Tan
  Joy Tan
  Sep 2, 2022 @ 07:32pm

HI Rick,

I found out I didn't have to do any STRConv() for the token. All is working now. Thanks so much.

All good cheers! Joy

© 1996-2022