-
Notifications
You must be signed in to change notification settings - Fork 626
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
Generic Microsoft Graph API Wrapper #22919
Conversation
@jwikman after our discussions on the sharepoint pull request, I created a small draft for a generic microsoft graph API wrapper. Maybe you can take a look at the current draft |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I am certainly looking forward to when its fully implemented.
Modules/System/MicrosoftGraph/src/MgAuthorization/MgGraphClientCredentials.Codeunit.al
Outdated
Show resolved
Hide resolved
Modules/System/MicrosoftGraph/src/MgAuthorization/MgGraphClientCredentials.Codeunit.al
Outdated
Show resolved
Hide resolved
Modules/System/MicrosoftGraph/src/helper/MgOperationResponse.Codeunit.al
Outdated
Show resolved
Hide resolved
Modules/System/MicrosoftGraph/src/helper/MgOperationResponse.Codeunit.al
Outdated
Show resolved
Hide resolved
Modules/System/MicrosoftGraph/src/helper/MgOperationResponse.Codeunit.al
Outdated
Show resolved
Hide resolved
Modules/System/MicrosoftGraph/src/helper/MgOperationResponse.Codeunit.al
Outdated
Show resolved
Hide resolved
Modules/System/MicrosoftGraph/src/helper/MicrosoftGraphDiagnostics.codeunit.al
Outdated
Show resolved
Hide resolved
Modules/System/MicrosoftGraph/src/helper/MicrosoftGraphHttpContent.Codeunit.al
Outdated
Show resolved
Hide resolved
Modules/System/MicrosoftGraph/src/helper/MicrosoftGraphHttpContent.Codeunit.al
Outdated
Show resolved
Hide resolved
Modules/System/MicrosoftGraph/src/helper/MicrosoftGraphRequestHelper.Codeunit.al
Outdated
Show resolved
Hide resolved
And I could need some help/idea/draft in writing tests, since I don't know how to write helpful tests for such a generic API wrapper. |
@darjoo could you maybe take a short look at this PR and evaluate if such a module could be accepted in general and if you agree with the basic architecture, before I start improving the code for BC22 and fixing the open comments |
@pri-kise Yeah, we will accept the module. Few things that pop up:
Overall it looks good besides the top few for now. If you need further discussions/reviews, ping Jesper and he'll find someone on the team. I'll be away for the next two weeks :) |
I copied some logic of the other API Modules. I've split the modules, to enable later usage for the sharepoint module. Currently the sharepoint module makes use of the old Rest Api, but I'd like to make it possible to create a sharepoint module v2 that uses the graph api module. Could you maybe elaborate why 'CreateAuthorizationWithClientCredentials' should only be used OnPrem? |
Understandable, we're trying to get away from adding events as a method to just test/mock and leaving those events in prod. I don't have the exact way we should go about testing this at the moment, but I'm sure we can come up with something better. Which has been a very bad habit of doing things especially from BaseApp days. Test specific events, which inturn can be used also in prod. Especially for Sounds good, probably not a v2 of the module but updating the internals to use this (if possible). As far as I know, the way we've integrated with graph has been to use the token directly provided by platform. Is there reason to be using another tenant/client id & secret? (There may be a valid case, I just don't know what it is) Whereas, OnPrem doesn't sign in with graph automatically, and as such will need to provide their own client Id, client secret. |
I was thinking about providing the possibility for other partners to create specific app registrations for any specific scenario where they want to assign a limited group of API permissions in the specific app registration. |
@darjoo as discussed in #12960, no-one else but Microsoft should use the tokens provided by platform. It also gives us the possibility to add the permissions needed for the specific scenario, as @pri-kise writes. |
8846d86
to
4dd13a2
Compare
4dd13a2
to
2d52e20
Compare
@darjoo could you now take a deeper look into the module please? I removed the events as requested. If you want to have a prefix I can replace any name with "Microsoft Graph" with Mg e.g. |
Modules/System/MicrosoftGraph/src/helper/MicrosoftGraphUriBuilder.Codeunit.al
Outdated
Show resolved
Hide resolved
Let's try to get this ready for showtime with 2023 Wave 2. |
I am sorry, @pri-kise; the update emails got dropped in my spam filter and I completely lost track. You have done some really nice restructuring, which is being reviewed by MS, as far as I can see. As far as tests go, you cannot actually test the requests, but what often happens is that on the one hand we create a request body, intercept it and verify its structure and information, and on the other we mimic a response and test the handling of the responses. For response testing, you can use OperationResponse.SetHttpResponse(HttpResponseMessage); where OperationResponse is codeunit 9156 "Mg Operation Response" and the HttpResponseMessage is a message of your creation. This will need to encompass various scenarios including successful ones and likely failed ones (401, 403, 404, 500, etc.) to test exception handling. Intercepting requests is trickier, since as @darjoo said, using events to intercept this presents security issues. Interface structures might be an option here; Vjekoslav Babic has some good examples, if you need them. That way, your test app can use injection to mimic the request and run tests on it. Depending on how you implement it, this might expose similar security issues, so it might require some extra thought. |
d207ec4
to
4cf51e3
Compare
@PeterConijn, @darjoo I tried to add some Basic Tests for this generic module. Maybe you can take a look if this is the right direction |
29a2826
to
9b0e74d
Compare
That looks good. With the implementations in your tests that pretend to send back responses, you can test whether the module handles those responses in the expected manner. I love it! |
Hi @pri-kise, what do you think? Is this one ready to get processed? Should we make an attempt to get it checked in? |
Modules/System Tests/MicrosoftGraph/src/DummyHttpResponseMessage.Codeunit.al
Outdated
Show resolved
Hide resolved
Yes I'd like to make an attempt - I'll be on vacation during the first 3 weeks of september. |
I am putting this one on hold, until we've got a "HttpClient" wrapper module draft from @ajkauffmann, as this PR too contains a wrapper. I want to see if cannot use AJs. We should get a PR any day now! |
Okay. I was hoping that this module will be there for directions.. |
As @JesperSchulz said, it will be there very soon. |
Update: The Rest Client module has been checked into the master branch. Once this repository is switched to master, you can uptake it in your module. |
2272ab3
to
4804ecd
Compare
I udpated my PR with the Rest Client Module. Addtionally i tried to add an OAuth Authentitaction with ClientCredentials to the Rest Client Module. @JesperSchulz @ajkauffmann I could need some feedback. |
Closed in favour of PR microsoft/BCApps#318 |
This is a first draft for a generic microsoft graph api wrapper as mentioned in issue #329 This PR replaces the PR (microsoft/ALAppExtensions#22919) on the old repository ALAppExtensions. Fixes #329 Work item: AB#477759 --------- Co-authored-by: Kilian Seizinger <[email protected]> Co-authored-by: Jesper Schulz-Wedde <[email protected]>
This is a first draft for a generic microsoft graph api wrapper as mentioned in issue microsoft/BCApps#329
Dummy Script for Testing