1
votes

I am trying to make a widget into a web app(Youtrack) that would call Microsoft Graph API to retrieve data from Teams(that is the only way I found something like this could work).

The widget can only work with JS, so I found some materials on graph API JS implementation. First of all I register an app in azure to get client-id and then from these sources I put together some code that would just do one simple API request.

Here are the materials:

https://docs.microsoft.com/en-us/graph/toolkit/providers/teams (teams provider)

https://docs.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=Javascript (setup provider)

https://docs.microsoft.com/en-us/graph/teams-list-all-teams (API usage)

<script src="https://unpkg.com/@microsoft/teams-js/dist/MicrosoftTeams.min.js" crossorigin="anonymous"></script>
<script src="https://unpkg.com/@microsoft/mgt/dist/bundle/mgt-loader.js"></script>

...

<script type="text/javascript">
const clientId = "xyz"; // Client Id of the registered application
const callback = (errorDesc, token, error, tokenType) => { };
const graphScopes = ["user.read", "mail.send"];
const userAgentApplication = new MSAL.UserAgentApplication(clientId, undefined, callback);
const authProvider = new MicrosoftGraph.ImplicitMSALAuthenticationProvider(userAgentApplication, graphScopes);

const options = {
   authProvider,
};
const Client = MicrosoftGraph.Client;
const client = Client.initWithMiddleware(options);
client.api('/teams/{group-id}').get(); //{group-id} - here is a group id
</script>

I am probably far from the correct solution, but just from the documentation I cannot figure out how to perform this simple task.

The script now says: " MSAL is not defined".

I might use this whole thing wrong, if anyone could point me in the right direction I would be really thankful.

1

1 Answers

0
votes

@petr Nohejl - Try this JS Sample code. This has authentication also handled. This will be good start for you.