Teams Bot - MS Graph Auth - Java - microsoft-graph-api

I'm looking at this code sample to connect a Teams Bot to the Microsoft Graph.
https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/java_springboot/46.teams-auth
The code is working with an old version of microsoft-graph.
When I update it to 5.35.0, I can no longer connect to MS Graph because the authentication classes have changed.
I can no longer pass a Token inside the HTTP Header.
Can someone update the code to show me (or give me directions) how to connect the Bot to MS Graph with a user permission consent ?
Thanks

Related

Connecting PowerBI to Microsoft Graph or Azure AD

My customer needs to connect their users and groups within Office 365 & Azure AD to Power BI, so they can show a report of the amount of users with certain licenties, the amount of RDS users and what type mailbox the users are using.
The whole proces needs to go automatically, so when PowerBI is opened the data is already ready for them and up to date.
My solution was the following:
Source,Office 365 & Azure AD), send the data to an API(Microsoft Graph)
Microsoft Graph exposes a webendpoint which another application can get the data from, IF they provide the correct OAuth2 bearer token-.
Access the webendpoint with Power BI and get the data when Power BI get's opened.
PROBLEM
I don't know how to refresh an OAuth2 token in Power BI, can someone help me?
Connecting to Microsoft Graph REST APIs from Power Query isn't recommended or supported.
Read more here: https://learn.microsoft.com/en-us/power-query/connecting-to-graph

MS Graph API Authentication | MS Teams | Bot framework

I am new to bot development. I am working on creating a MS Teams bot using bot framework. The bot will be installed in ‘Personal’ scope in Teams, and it doesn’t have any tab / messaging extension etc. Once installed, I want to get the list of all the members/ channels/ Notification updates (i.e. members added/deleted etc.). As per the different documentation, I can get the list using Graph API.
List members of team - Microsoft Graph v1.0 | Microsoft Docs
List members of a channel - Microsoft Graph v1.0 | Microsoft Docs
To achieve this, I need the token that will be passed in API. I am not sure how to implement that. I have followed the instructions mentioned in Add authentication to a bot in Bot Framework SDK - Bot Service | Microsoft Docs. There was a step to add ‘Add OAuth Connection Settings’ and there were multiple options in ‘Service Provider’. I selected ‘Azure Active Directory v2’. After doing that, it works and I can get the token, but it only works if during login, I user my azure directory credentials. I have a Microsoft account linked with my MS Teams which id different than the Azure account. A user in team can have a Microsoft account / work / office account so this needs to work for everyone so what would be the correct ‘Service Provider’ option that will work for all accounts?
I was thinking that the flow should be like:
When clicks on ‘Add’ button to install the app in Teams
Once added, bot will prompt for Graph API permission using OAuth.
Once user gives the permission, I can use the token to call graph APIs.
I have also looked at the following tutorials:
How to use Bot Framework Composer to build low-code Microsoft Teams bots (Part 1)
Get user profile information in your Microsoft Teams bot with Microsoft Graph (Part 2) - YouTube
But after performing all the steps, when I try to login, it says – ‘This action can't be performed since the app does not exist or has been uninstalled.’.
I am not getting a clear approach on how to proceed with it.
As #Maxim has also suggested, if you want to have a bot that should run multitenant you need to put tenant Id as common in OAuth Setting in Azure bot. As the value suggest it isn't going to specific to single tenant and Redirect Uri should be set to https://token.botframework.com/.auth/web/redirect in app registration.
This is it, you don't need to add anything.
This is also mention in the doc --
We have some sample around it as well that shows how to use Graph API with the bot -
https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/csharp_dotnetcore/24.bot-authentication-msgraph
You can setup this one and update the Graph calls to get member of team or channels.

Getting "MailboxNotEnabledForRESTAPI" While trying to use MS Graph APIs

We have used MS Graph API(MSAL) in one SAP Ui5 Application and have implemented Mail api, Calender api and MailboxSetting apis so far. It was working fine till Nov 2020 (Last checked in Nov 30 2020).
Suddenly this application keeps throwing the error "{"error":{"code":"MailboxNotEnabledForRESTAPI","message":"REST API is not yet supported for this mailbox."}}".
Though we have not changed a single code or any changes has been done in Azure portal or in the envirmental set up.We do have a Hybrid envirment mailbox set up.
The strange thing is the same APIs are working in MS Graph Explorer but not from our custom Apps. But when we use the token generated by Graph Explorer, APIs works from our custom apps also.
We compared the both tokens using jwt.ms. Scopes and other attributes are the same. Only 'wids' attribute is not present in our custom App's Token(We are using Implicit Grant flow).
which flow do MS Graph Explorer use, so it works there ?(If Authorization
flow is the issue).
Is it that only Graph Explorer is allowed to make API calls to On-Premise
Mailbox and the custom applicationa are not?
Is there any other factor, we should consider to solve this ?
Thank You,
Arpita
This error happens when trying to access a mailbox that is not hosted in EXO. Check where your target mailbox is hosted and use auto discover to locate the right endpoint for that environment.

Accessing and creating Teams Chats via Graph API

I'm going over the Microsoft Teams section of the Graph API and trying to find out how to do two things:
Create a new chat, giving it a topic that correlates to an entity in our app (essentially creating a chat around an entity), invite specific users into it, and send messages to the chat.
Access the currently logged-in user's private chats, filtered by their topic, and show their contents inside our app.
For #2, it looks like it should be possible using beta endpoint of the Graph API, but I get 403 Forbidden errors both in the Graph Explorer when trying to access https://graph.microsoft.com/beta/me/chats, and in my own app, after enabling the Chat.Read permissons for it.
For #1, it looks like the API doesn't officially support creating new chats at all.
Is there any approach we can use to create and manage chats? Is there an alternative, perhaps not MicrosoftGraph-based API?
as you mention, the ms graph doesn't yet support initiating group chat. You would use the MS Bot Framework for this: https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bot-conversations/bots-conv-proactive
I see the docs on these Chat api do exist, but they are not present in the Graph Explorer. I tired testing them in the OfficeApiEditor tool with a v2.0 App Registration and Delegated permissions (Chat.Read) and i get this:
Failure - Status Code 500
"code": "InternalServerError",
"message": "Error while processing response.",
so maybe it will take some time before they are really available in beta.
In MS teams, there is a api called ChatMessage to post a message to a chat(only if the chat already exist or started). But, there is no api to create/start a new chat. I have raised a feature request. Do vote for this to suggest this idea to Microsoft.
https://microsoftteams.uservoice.com/forums/913786-microsoft-teams-free/suggestions/38776681-it-would-be-awesome-l-if-there-is-an-api-functiona

Reading emails from Exchange online in c#.net using Office 365 API

I am trying to read emails from Exchange online through a Office 365 API.with using my username and password for authentication.
Is it possible to access the O365 api? (only using user credentials)
How can I do that? Anyone can help is appreciated.
If your exchange online is part of Office 365, you should definitively take a look here : http://dev.office.com
You will find many tutorials to get access to your mails.
Take a look here : http://dev.office.com/getting-started/office365apis
It uses the Microsoft Graph to query your mailbox and retrives messages :
https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages
The authentication process is provided byt Azure Active Directory, through ADAL SDK.
In Visual Studio, you can create easily an application, and then call the submenu 'Add connected services' and you're done !

Resources