Bert
  • Bert
  • 50.75% (Neutral)
  • Newbie Topic Starter
2 years ago
https://www.emailarchitect.net/eagetmail/ex/d/19.aspx#delphi-retrieve-email-using-gmail-g-suite-oauth-2-0-from-imap4-server-with-service-account-example 

I have created both a json type private key and a p12 private key. The example uses the p12 key. When using this I can succesfully authenticate. However when I use the private key from the json file I can not. The reason is that the signature remains empty when calculating this using jwt.SignRs256WithPrivateKey(privateKey, header + '.' + playload)

To use the json private key I have modified the GenerateRequestData method (see the above mentioned example page ) in the following way:



// load service account certificate to sign request data
// pfxPath := 'C:\test\myservice.p12';
// cert.LoadFromFile(pfxPath, 'notasecret', CRYPT_USER_KEYSET);
// signature := jwt.SignRs256(cert.DefaultInterface, header + '.' + playload);

JSONText := TFile.ReadAllText('C:\test\myservice.json');
JSONValue := TJSONObject.ParseJSONValue(JSONText);

if JSONValue is TJSONObject then
begin
JSONObject := TJSONObject(JSONValue);

if JSONObject.TryGetValue('private_key', privateKey) then
memoLog.Lines.Add('private_key found')
else
memoLog.Lines.Add('private_key property not found in the JSON.');
end
else
begin
memoLog.Lines.Add('Invalid JSON format.');
end;


signature := jwt.SignRs256WithPrivateKey(privateKey, header + '.' + playload);



both de myservice.p12 and de myservice.json are created as descibed in section 'Enable “Domain-wide delegation” and create service key' of the above mentioned example page.

p.s I added the following vars to the var section of the GenerateRequestData method:

JSONText: string;
JSONObject: TJSONObject;
JSONValue: TJSONValue;

I also added the following uses to the uses section:

System.JSON, IOUtils

What am I doing wrong i.e. why is de signature not correctly calculated?
ivan
  • ivan
  • 100% (Exalted)
  • Administration
2 years ago
Hi, it looks like there is a problem with private key, so the SignRs256WithPrivateKey returns empty string.

The problem was solved by using latest version of EAGetMail.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.