Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth2.GetClaims() #2363

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/System Application/App/OAuth2/OAuth2.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,16 @@ codeunit 501 OAuth2
OAuth2Impl.AcquireOnBehalfOfTokensByTokenCache(ClientId, ClientSecret, LoginHint, RedirectURL, Scopes, TokenCache, AccessToken, IdToken, NewTokenCache);
end;

/// <summary>
/// Gets the Claims Set from a JSON Web Token (JWT).
/// </summary>
/// <param name="JWT">The JSON Web Token.</param>
/// <returns>The JWT Claims Set.</returns>
procedure GetClaims(JWT: SecretText) Result: JsonObject
begin
exit(OAuth2Impl.GetClaims(JWT));
end;

/// <summary>
/// Get the last error message that happened during acquiring of an access token.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions src/System Application/App/OAuth2/OAuth2Impl.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace System.Security.Authentication;

using System;
using System.Text;
using System.Environment;
using System.Utilities;

Expand Down Expand Up @@ -1427,6 +1428,25 @@ codeunit 502 OAuth2Impl
IdToken := CompoundToken.IdToken;
end;

[NonDebuggable]
procedure GetClaims(JWT: SecretText) Result: JsonObject
var
Base64Convert: Codeunit "Base64 Convert";
PlainTextJWT: Text;
Base64Text: Text;
begin
if JWT.IsEmpty() then
exit;
PlainTextJWT := JWT.Unwrap();
if PlainTextJWT.Split('.').Count() < 3 then
exit;
Base64Text := PlainTextJWT.Split('.').Get(2);
Base64Text := Base64Text.Replace('-', '+').Replace('_', '/');
if StrLen(Base64Text) mod 4 <> 0 then
Base64Text := PadStr(Base64Text, StrLen(Base64Text) + (4 - StrLen(Base64Text) mod 4), '=');
Result.ReadFrom(Base64Convert.FromBase64(Base64Text))
end;

procedure GetLastErrorMessage(): Text
begin
exit(AuthFlow.LastErrorMessage());
Expand Down
8 changes: 7 additions & 1 deletion src/System Application/App/OAuth2/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
"name": "Environment Information",
"publisher": "Microsoft",
"version": "26.0.0.0"
},
{
"id": "0846d207-5dec-4c1b-afd8-6a25e1e14b9d",
"name": "Base64 Convert",
"publisher": "Microsoft",
"version": "26.0.0.0"
}
],
"screenshots": [],
Expand All @@ -51,4 +57,4 @@
"includeSourceInSymbolFile": true
},
"target": "OnPrem"
}
}
Loading