AleksandrRogov / DynamicsWebApi

DynamicsWebApi is a Microsoft Dataverse Web API helper library for JavaScript & TypeScript
MIT License
269 stars 58 forks source link

V2 Timeline & support for MSAL.js #83

Closed jync closed 3 years ago

jync commented 3 years ago

Just planning ahead. I can see v2 is coming and I can see MS is deprecating ADAL.js. What is DynamicsWebApi's timeline on these items? Is there a way we could preview v2?

AleksandrRogov commented 3 years ago

hi @jync, DynamicsWebApi does not depend on ADAL, it just needs a token. It can even be a custom authentication functionality. So, I am not worried about that.

You can preview v2 in typescript branch, it should be visible to everyone. Some parameters and return objects will most likely change but not too much. So, it should give you an idea what to expect from v2.

pixelpaulaus commented 2 years ago

anyone have some examples of using the new msal-node? i cant get it to work

AleksandrRogov commented 2 years ago

I am using this code for my testing (it's TypeScript):

import * as DynamicsWebApi from "dynamics-web-api";
import * as MSAL from "@azure/msal-node";
import Config from "./config";

const authorityUrl = 'https://login.microsoftonline.com/<GUID HERE>';

const msalConfig = {
    auth: {
        clientId: Config.clientId,
        authority: authorityUrl,
        clientSecret: Config.secret,
        knownAuthorities: ["login.microsoftonline.com"]
    }
}

const cca = new MSAL.ConfidentialClientApplication(msalConfig);

//add a callback as a parameter for your function
const acquireToken = (dynamicsWebApiCallback: DynamicsWebApi.OnTokenAcquiredCallback) => {
    cca.acquireTokenByClientCredential({
        scopes: ["https://<YOURORG>.crm.dynamics.com/.default"]
    }).then(response => {
        //call DynamicsWebApi callback only when a token has been retrieved
        dynamicsWebApiCallback(response.accessToken);
    }).catch((error) => {
        console.log(JSON.stringify(error));
    });
}

const config: DynamicsWebApi.Config = {
    webApiUrl: "https://<YOURORG>.crm.dynamics.com/api/data/v9.2/",
    onTokenRefresh: acquireToken,
    useEntityNames: true
};

const dynamicsWebApi = new DynamicsWebApi(config);
AleksandrRogov commented 2 years ago

@pixelpaulaus sorry forgot to ping, my reply is above.

pixelpaulaus commented 2 years ago

that helped a great deal, thanks

AleksandrRogov commented 2 years ago

glad it helped!