Skip to content

Commit

Permalink
Use GetResponse as UpdateStatus is just async confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
magnushar committed Dec 4, 2024
1 parent 60be83e commit c24ddcd
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 341 deletions.
4 changes: 2 additions & 2 deletions Apps/W1/EDocumentConnectors/Logiq/app/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"id": "e1d97edc-c239-46b4-8d84-6368bdf67c8b",
"name": "E-Document Core",
"publisher": "Microsoft",
"version": "24.0.0.0"
"version": "26.0.0.0"
}
],
"internalsVisibleTo": [
Expand All @@ -43,5 +43,5 @@
"features": [
"TranslationFile"
],
"target": "OnPrem"
"target": "Cloud"
}
23 changes: 14 additions & 9 deletions Apps/W1/EDocumentConnectors/Logiq/app/src/Auth.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
namespace Microsoft.EServices.EDocumentConnector.Logiq;
codeunit 6430 Auth
{

Permissions =
tabledata "Connection Setup" = r,
tabledata "Connection User Setup" = rm;

internal procedure SetIsolatedStorageValue(var ValueKey: Guid; Value: SecretText; TokenDataScope: DataScope)
begin
if IsNullGuid(ValueKey) then
Expand Down Expand Up @@ -77,9 +82,9 @@ codeunit 6430 Auth
BodyText: SecretText;
begin
LogiqConnectionSetup.Get();
LogiqConnectionUserSetup.Get(UserId());
LogiqConnectionUserSetup.Get(UserSecurityId());

if (not IsNullGuid(LogiqConnectionUserSetup."Refresh Token")) and (LogiqConnectionUserSetup."Refresh Token Expiration" > (CurrentDateTime + 60 * 1000)) then
if (not IsNullGuid(LogiqConnectionUserSetup."Refresh Token - Key")) and (LogiqConnectionUserSetup."Refresh Token Expiration" > (CurrentDateTime + 60 * 1000)) then
BodyText := SecretText.SecretStrSubstNo(this.RefreshTokenBodyTok, LogiqConnectionSetup."Client ID", LogiqConnectionSetup.GetClientSecret(), LogiqConnectionUserSetup.GetRefreshToken())
else
BodyText := SecretText.SecretStrSubstNo(this.CredentialsBodyTok, LogiqConnectionSetup."Client ID", LogiqConnectionSetup.GetClientSecret(), LogiqConnectionUserSetup.Username, LogiqConnectionUserSetup.GetPassword());
Expand All @@ -89,10 +94,10 @@ codeunit 6430 Auth

internal procedure CheckUserCredentials(var LogiqConnectionUserSetup: Record "Connection User Setup")
begin
if not LogiqConnectionUserSetup.Get(UserId()) then
if not LogiqConnectionUserSetup.Get(UserSecurityId()) then
Error(this.NoUserSetupErr);

if (LogiqConnectionUserSetup.Username = '') or (IsNullGuid(LogiqConnectionUserSetup."Password")) then
if (LogiqConnectionUserSetup.Username = '') or (IsNullGuid(LogiqConnectionUserSetup."Password - Key")) then
Error(this.MissingCredentialsErr);
end;

Expand Down Expand Up @@ -146,9 +151,9 @@ codeunit 6430 Auth
var
LogiqConnectionUserSetup: Record "Connection User Setup";
begin
LogiqConnectionUserSetup.Get(UserId());
this.SetIsolatedStorageValue(LogiqConnectionUserSetup."Access Token", AccessToken, DataScope::User);
this.SetIsolatedStorageValue(LogiqConnectionUserSetup."Refresh Token", RefreshToken, DataScope::User);
LogiqConnectionUserSetup.Get(UserSecurityId());
this.SetIsolatedStorageValue(LogiqConnectionUserSetup."Access Token - Key", AccessToken, DataScope::User);
this.SetIsolatedStorageValue(LogiqConnectionUserSetup."Refresh Token - Key", RefreshToken, DataScope::User);
LogiqConnectionUserSetup."Access Token Expiration" := AccessTokExpires;
LogiqConnectionUserSetup."Refresh Token Expiration" := RefreshTokExpires;
LogiqConnectionUserSetup.Modify(false);
Expand All @@ -163,9 +168,9 @@ codeunit 6430 Auth
var
LogiqConnectionUserSetup: Record "Connection User Setup";
begin
if not LogiqConnectionUserSetup.Get(UserId()) then
if not LogiqConnectionUserSetup.Get(UserSecurityId()) then
Error(this.NoUserSetupErr);
if IsNullGuid(LogiqConnectionUserSetup."Access Token") or (LogiqConnectionUserSetup."Access Token Expiration" < (CurrentDateTime + 5 * 60 * 1000)) then
if IsNullGuid(LogiqConnectionUserSetup."Access Token - Key") or (LogiqConnectionUserSetup."Access Token Expiration" < (CurrentDateTime + 5 * 60 * 1000)) then
this.GetTokens();
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ page 6430 "Connection Setup"
LogiqConnectionUserSetup: Record "Connection User Setup";
LoqiqConnectionUserSetupPage: Page "Connection User Setup";
begin
LogiqConnectionUserSetup.FindUserSetup(CopyStr(UserId(), 1, 50));
LogiqConnectionUserSetup.FindUserSetup(UserSecurityId());
LoqiqConnectionUserSetupPage.SetRecord(LogiqConnectionUserSetup);
LoqiqConnectionUserSetupPage.Run();
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,21 @@ table 6430 "Connection Setup"
{
field(1; PK; Code[20])
{
DataClassification = CustomerContent;
DataClassification = SystemMetadata;
}
field(21; "Authentication URL"; Text[100])
{
Caption = 'Authorization URL';
DataClassification = CustomerContent;
ToolTip = 'Specifies the Authorization URL.';
}
field(22; "Base URL"; Text[100])
{
Caption = 'Base URL';
DataClassification = CustomerContent;
ToolTip = 'Specifies the Base URL.';
}
field(25; "File List Endpoint"; Text[100])
{
Caption = 'File List Endpoint';
DataClassification = CustomerContent;
ToolTip = 'Specifies the Endpoint to list available files.';
}
field(31; "Client ID"; Text[100])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ page 6431 "Connection User Setup"
if this.PasswordTxt = '' then
Rec.DeletePassword()
else
this.LogiqAuth.SetIsolatedStorageValue(Rec.Password, this.PasswordTxt, DataScope::User);
this.LogiqAuth.SetIsolatedStorageValue(Rec."Password - Key", this.PasswordTxt, DataScope::User);

if this.IsFullCredentials() then
this.CheckCredentialsAndUpdateTokens();
Expand Down Expand Up @@ -108,8 +108,8 @@ page 6431 "Connection User Setup"

trigger OnOpenPage()
begin
if not IsNullGuid(Rec.Password) then
if this.LogiqAuth.HasToken(Rec.Password, DataScope::User) then
if not IsNullGuid(Rec."Password - Key") then
if this.LogiqAuth.HasToken(Rec."Password - Key", DataScope::User) then
this.PasswordTxt := '*';
end;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,61 @@ table 6431 "Connection User Setup"

fields
{
field(1; "User ID"; Text[50])
field(1; "User Security ID"; Guid)
{
Caption = 'User ID';
Caption = 'User Security ID';
DataClassification = EndUserIdentifiableInformation;
TableRelation = User."User Name";
TableRelation = User;
}
field(2; "User ID"; Text[50])
{
Caption = 'User ID';
ToolTip = 'Specifies the user ID.';
FieldClass = FlowField;
CalcFormula = lookup(User."User Name" where("User Security ID" = field("User Security ID")));
}
field(21; Username; Text[100])
{
Caption = 'Username';
DataClassification = EndUserIdentifiableInformation;
ToolTip = 'Specifies the user name.';
}
field(22; Password; Guid)
field(22; "Password - Key"; Guid)
{
Caption = 'Password';
ToolTip = 'Specifies the password key.';
DataClassification = SystemMetadata;
}
field(23; "Access Token"; Guid)
field(23; "Access Token - Key"; Guid)
{
Caption = 'Access Token';
Caption = 'Access Token Key';
ToolTip = 'Specifies the access token key.';
DataClassification = SystemMetadata;
}
field(24; "Access Token Expiration"; DateTime)
{
Caption = 'Access Token Expires At';
ToolTip = 'Specifies the access token expiration date.';
DataClassification = SystemMetadata;
}
field(25; "Refresh Token"; Guid)
field(25; "Refresh Token - Key"; Guid)
{
Caption = 'Refresh Token';
Caption = 'Refresh Token Key';
ToolTip = 'Specifies the refresh token key.';
DataClassification = SystemMetadata;
}
field(26; "Refresh Token Expiration"; DateTime)
{
Caption = 'Refresh Token Expires At';
ToolTip = 'Specifies the refresh token expiration date.';
DataClassification = SystemMetadata;
}
field(31; "API Engine"; Enum "API Engine")
{
Caption = 'API Engine';
DataClassification = CustomerContent;
ToolTip = 'Specifies the value of the API Engine field.';
DataClassification = SystemMetadata;
trigger OnValidate()

begin
case Rec."API Engine" of
Rec."API Engine"::Engine1:
Expand Down Expand Up @@ -85,7 +99,7 @@ table 6431 "Connection User Setup"
}
keys
{
key(PK; "User ID")
key(PK; "User Security ID")
{
Clustered = true;
}
Expand All @@ -94,57 +108,57 @@ table 6431 "Connection User Setup"
var
LogiqAuth: Codeunit Auth;

internal procedure FindUserSetup(UserID: Text[50])
internal procedure FindUserSetup(UserSecurityID: Guid)
begin
if not Rec.Get(UserID) then begin
if not Rec.Get(UserSecurityID) then begin
Rec.Init();
Rec."User ID" := UserID;
Rec.Insert(false);
Rec."User Security ID" := UserSecurityID;
Rec.Insert();
end;
end;

internal procedure GetPassword(): SecretText
var
ClientSecret: SecretText;
begin
this.LogiqAuth.GetIsolatedStorageValue(Rec.Password, ClientSecret, DataScope::User);
this.LogiqAuth.GetIsolatedStorageValue(Rec."Password - Key", ClientSecret, DataScope::User);
exit(ClientSecret);
end;

internal procedure GetAccessToken(): SecretText
var
AccessToken: SecretText;
begin
this.LogiqAuth.GetIsolatedStorageValue(Rec."Access Token", AccessToken, DataScope::User);
this.LogiqAuth.GetIsolatedStorageValue(Rec."Access Token - Key", AccessToken, DataScope::User);
exit(AccessToken);
end;

internal procedure GetRefreshToken(): SecretText
var
RefreshToken: SecretText;
begin
this.LogiqAuth.GetIsolatedStorageValue(Rec."Refresh Token", RefreshToken, DataScope::User);
this.LogiqAuth.GetIsolatedStorageValue(Rec."Refresh Token - Key", RefreshToken, DataScope::User);
exit(RefreshToken);
end;

internal procedure DeleteUserTokens()
begin
if (not IsNullGuid(Rec."Access Token")) then
if IsolatedStorage.Contains(Rec."Access Token", DataScope::User) then
IsolatedStorage.Delete(Rec."Access Token", DataScope::User);
if (not IsNullGuid(Rec."Refresh Token")) then
if IsolatedStorage.Contains(Rec."Refresh Token", DataScope::User) then
IsolatedStorage.Delete(Rec."Refresh Token", DataScope::User);
if (not IsNullGuid(Rec."Access Token - Key")) then
if IsolatedStorage.Contains(Rec."Access Token - Key", DataScope::User) then
IsolatedStorage.Delete(Rec."Access Token - Key", DataScope::User);
if (not IsNullGuid(Rec."Refresh Token - Key")) then
if IsolatedStorage.Contains(Rec."Refresh Token - Key", DataScope::User) then
IsolatedStorage.Delete(Rec."Refresh Token - Key", DataScope::User);
Rec."Access Token Expiration" := 0DT;
Rec."Refresh Token Expiration" := 0DT;
Rec.Modify(false);
Rec.Modify();
end;

internal procedure DeletePassword()
begin
if (not IsNullGuid(Rec.Password)) then
if IsolatedStorage.Contains(Rec.Password, DataScope::User) then
IsolatedStorage.Delete(Rec.Password, DataScope::User);
if (not IsNullGuid(Rec."Password - Key")) then
if IsolatedStorage.Contains(Rec."Password - Key", DataScope::User) then
IsolatedStorage.Delete(Rec."Password - Key", DataScope::User);
end;

var
Expand Down

This file was deleted.

64 changes: 0 additions & 64 deletions Apps/W1/EDocumentConnectors/Logiq/app/src/EDocument.PageExt.al

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ tableextension 6430 "E-Document" extends "E-Document"
{
fields
{
field(6380; "Logiq External Id"; Text[50])
field(6430; "Logiq External Id"; Text[50])
{
Caption = 'Logiq External Id';
DataClassification = CustomerContent;
DataClassification = SystemMetadata;
Editable = false;
ToolTip = 'Specifies document id in Logiq system';
}
Expand Down
Loading

0 comments on commit c24ddcd

Please sign in to comment.