How to call an authenticated service, like you can do with spfx

I have a web service that uses app azure authentication. As you know using SPFX, you can add the possibility to use ADAL to authenticate seamlessly through Sharepoint to the authenticated web service.

The administrator must approve this kind of call but once it's approved in the Sharepoint admin center, it works great.

How can I do the same thing within a Plumsail Sharepoint Form? Is there any javascript library and example? Thx.

Hello @Miguel,

Yes, it is possible.

Forms exposes spfxContext variable for custom JS-code that can be used to obtain aadHttpClientFactory:

spfxContext.aadHttpClientFactory 

Learn more here:

Hi @mnikitina
Great to know that we have this property / object spfxContext.

1/ Could you give me an example in Plumsail Forms or where can I find more Plumsails documentation please?
Can I do simply?
spfxContext.aadHttpClientFactory
.getClient('https://contoso.azurewebsites.net')
.then((client: AadHttpClient): void => {
// connect to the API
});
it's
2/ Probably more important than first point, as you know, to use some APIs you have to give permissions to that API in the Sharepoint admin center, how would we do it with Plumsail Forms?
With SPFX, the request for this kind of permission is automatic if you request this in the configuration of SPFX.

Thx

@Miguel,

A code example can be found here:

But instead of this.context, you should use spfxContext:

this.context.aadHttpClientFactory
      .getClient('https://contoso.azurewebsites.net')
      .then((client: AadHttpClient): void => {
        // connect to the API
      });

Should be:

spfxContext.aadHttpClientFactory
      .getClient('https://contoso.azurewebsites.net')
      .then(() => {
        // connect to the API
      });
1 Like

I continue to have doubts about this part, because if you use ADAL it's to authentiate automatically from Sharepoint, to use the single sign-on:

Could you give me more insight please? I would appreciate.

Dear @Miguel,
I've consulted with the dev team and according to our devs, there are two options:
Option 1 : Create own SPFx solution with the required permissions, add it to the app catalog, and grant the permissions. Once the request is approved, the permissions become granted to all SPFx solutions, not to the one that has requested them:

Option 2 : Grant permissions with Microsoft 365 CLI:
https://pnp.github.io/cli-microsoft365/cmd/spo/serviceprincipal/serviceprincipal-grant-add/

1 Like

The first option whas what I thought would be the solution, but second one is another good option!, thx for taking your time answering me!!

1 Like