Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Bert  
#1 Posted : Thursday, August 10, 2023 4:38:16 AM(UTC)
Bert

Rank: Newbie

Groups: Registered
Joined: 8/10/2023(UTC)
Posts: 1
Netherlands
Location: Zoetermeer

I have created a test application based on the example https://www.emailarchite...-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:

<code snippet>

// 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<WideString>('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);

</code snippet>

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?

Edited by user Thursday, August 10, 2023 4:46:22 AM(UTC)  | Reason: Added var and uses modifications

ivan  
#2 Posted : Monday, August 14, 2023 10:50:17 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,148

Thanks: 9 times
Was thanked: 54 time(s) in 54 post(s)
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.

Edited by user Wednesday, August 16, 2023 2:28:28 AM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.075 seconds.

EXPLORE TUTORIALS

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