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

[BC Idea]: Get the claims from a SecretText JWT Token #2296

Closed
1 task done
jwikman opened this issue Nov 1, 2024 · 8 comments · Fixed by #2363
Closed
1 task done

[BC Idea]: Get the claims from a SecretText JWT Token #2296

jwikman opened this issue Nov 1, 2024 · 8 comments · Fixed by #2363
Assignees
Labels
Approved The issue is approved BCIdea Issue related to a BCIdea Integration GitHub request for Integration area

Comments

@jwikman
Copy link
Contributor

jwikman commented Nov 1, 2024

BC Idea Link

https://experience.dynamics.com/ideas/idea/?ideaid=e565077f-7b98-ef11-95f5-7c1e526e605f

Description

When troubleshooting OAuth and trying to figure out why an AccessToken is not being accepted by the resource you are trying to use it on, we have earlier been able to get the AccessToken in plain text and put it into jwt.ms (or any other similar tool) to parse the token and look into all the claims (see https://auth0.com/docs/secure/tokens/json-web-tokens/json-web-token-claims for more information).

Looking at the claims often explains why it does not work, like missing scopes, new configuration not in effect yet (things get cached a lot nowadays), etc.

With the switch to SecretText in the Oath2 module, we cannot get the AccessToken in plain text. Hence, we cannot parse the AccessToken to get the claims. :(

I suggest a new function in the OAuth2 module that has the AccessToken (SecretText) as parameter and returns the claims as a JsonObject.

On top of that we could also add new functions that returns common claims in an easier way, like expiration time (requested in https://experience.dynamics.com/ideas/idea/?ideaid=41f5d251-1a59-ee11-a81c-0022484c1d83).

I will provide the implementation for this BC Idea

  • I will provide the implementation for this BC Idea
@jwikman jwikman added the BCIdea Issue related to a BCIdea label Nov 1, 2024
@JesperSchulz
Copy link
Contributor

@WaelAbuSeada / @darjoo, is this justifiable from a security perspective? Please triage.

@jwikman
Copy link
Contributor Author

jwikman commented Nov 6, 2024

@WaelAbuSeada / @darjoo, I can create a draft PR for this if you want to see the implementation approach before making a decision on this?

@JesperSchulz
Copy link
Contributor

@WaelAbuSeada / @darjoo, I can create a draft PR for this if you want to see the implementation approach before making a decision on this?

That sounds like a good path forward! Let's do that 😊

jwikman added a commit to jwikman/BCApps that referenced this issue Nov 14, 2024
@jwikman
Copy link
Contributor Author

jwikman commented Nov 14, 2024

Ok, here's the draft: #2363

Not that much code, but essential when troubleshooting OAuth issues 🙂
More than once, this has shown that recent changes in the app registration were not being used yet...

@JesperSchulz JesperSchulz added Integration GitHub request for Integration area Approved The issue is approved labels Nov 15, 2024
@JesperSchulz
Copy link
Contributor

Draft went through security review. Issue approved.

@jwikman
Copy link
Contributor Author

jwikman commented Nov 15, 2024

Draft went through security review. Issue approved.

Cool, thanks!

Happy Friday! 🥳

@pri-kise
Copy link
Contributor

@jwikman I today found two procedures in the BaseApp, since they are used in this PR: microsoft/ALAppExtensions#27261

https://github.com/microsoft/BusinessCentralApps/blob/main/App/Layers/W1/BaseApp/System/SOAPWebServiceRequestMgt.Codeunit.al

If those return the same then they could maybe partially uptake the this new feature:
GetTokenDetailsAsNameBuffer
GetTokenDetailsAsJson

@jwikman
Copy link
Contributor Author

jwikman commented Feb 11, 2025

@pri-kise yes, they could probably do that.

I tried to use the GetTokenDetailsAsJson() function on a JWT token that worked with the new GetClaims() function, and it fails - without any error message. And since it is a NonDebuggable function, it's hard to figure out why...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved The issue is approved BCIdea Issue related to a BCIdea Integration GitHub request for Integration area
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants