Teams Bot Authenticate with Teams Current User - node.js

I am working on teams bot in node js i need to authenticate the user who invoke the message and get their access token to access the web api which use the same AAD can any one help me in this.

The Microsoft Graph Azure AD API should help you with managing Azure AD login and tokens.
You can also take a look at Authentication in bots for an overview of how auth works in the Bot Framework as well as related docs on setting up SSO.

Related

How to build a simple NodeJS login using Microsoft OAuth

I have followed this tutorial (https://medium.com/authpack/easy-google-auth-with-node-js-99ac40b97f4c) to create a simple Google OAuth and I have accomplished it successfully.
Now I am trying to do the same with Microsoft and I cannot.
I have ready a lot of posts about it, but I am failing.
I have one app in the Azure Dev Portal, I have tried to send the user to the URL https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={{my_clien_id}}&response_type=code id_token&scope=https://graph.microsoft.com/email, but I am receiving error messages only.
How can I have the user email using the Microsoft OAuth?
If you are looking for user email accounts as AD user accounts or office 365 accounts then you can go for Azure Active directory app.
If you are considering social logins like facebook or google or Microsoft then you need to search for Azure Ad B2C.
Here are some article which can help you:
Azure AD B2C
Azure AD

Azure bot interacting with authenticated messaging endpoint

I am developing an Azure bot for Microsoft teams, using Azure Bot Service, Bot registration channel setup. The messaging endpoint is an App Service that is authenticated with AAD login. Could some please help me understand how to call this authenticated endpoint from a bot? currently, I am testing it on Webchat and I get a 401 unauthorized error. I tried configuring the Oauth Setting in the bot as per this, but still getting 401.
Could someone please point to any concepts and documentation required here.
There is no need to enable the App service Authentication. Just follow this article to add authentication to your bot via Azure Bot service. Then logon is required when you use the bot.
Reference:
Azure AD integration with Bot Framework / teams
Microsoft Teams behaves somewhat differently than other channels in regards to OAuth and requires a few changes to properly implement authentication. Specifically an Invoke Activity is sent to the bot rather than the Event Activity used by other channels. This Invoke Activity must be forwarded to the dialog if the OAuthPrompt is being used. This is done by subclassing the TeamsActivityHandler and implementing handleTeamsSigninVerifyState. It is best advised to make use of the 46.teams-auth sample to set up OAuth in Teams.
Hope this helps.

Any other ways to login users in bot besides using sigin in cards?

I have gone through this doc:
https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-authentication?view=azure-bot-service-4.0
I can understand we can sign in users using sign in cards.
But is there any other ways to do that to sign in azure ad users instead of using bot internal login process?
I am using azure web chat client and .net core to code my bot. Any assistance is appreciated.
If you use a custom WebChat channel, you can auth users first on the web page and then use tokens based on your bot business logic. For details, you can refer to this demo.
What's more, though it is not recommended, Azure AD ROPC flow will work for all channels by Azure AD rest API or Azure AD SDK to auth users. As you need to require your users to input their username and passwords in this flow while your bot interacting with users, which will carry risks are not present in other flows. You should only use this flow when other more secure flows can't be used.
Hope it helps.

For what is Microsoft app ID and password used for?

I am trying to deploy my Azure Bot Service but I am kinda struggling to understand for what is Microsoft app ID and password used for? Can someone explain me these terms?
I was trying to find the answers online but unsuccessfully.
Thank you for any help.
This is the identity of the Bot Service.
You will notice in the App registrations of Azure Active Directory (AAD) that your Bot Service is in there. This is to give you the ability to Authenticate, Authorize and Audit (AAA) the Bot Service.
For example, you may want to provide access for your Bot Service to other services in your subscription, or other subscriptions also using the same AAD.
And so, the app has a set of credentials which it can use. The concept is similar to Managed Service Accounts in Windows Server.
The Microsoft app ID and Password are used to register the bot with the Azure Bot Service.
After you register it, those credentials will be used by the bot connector to authenticate the calls to your Bot's service and allow you to configure the bot with the different available channels.
Bot security is configured by the Microsoft App ID and Microsoft App Password that you obtain when you register your bot with the Bot Framework. These values are typically specified within the bot's configuration file and used to retrieve access tokens from the Microsoft Account service.

Manage user from Azure AD B2C using AD Graph API - secure access

We are building a Xamarin Native mobile apps and using Azure AD B2C for authenticating users using their social logins.
We decided use MSAL native library (Xamarin) for authenticating using B2C. And our mobile app required to manage(full access) the signed-in user profile. Since this feature isn't available in MSAL we have decided to go with ADAL for the time being. Followed the instruction provided in the link below and the sample works. But I started experimenting by deleting the API access provided in the application (created in b2c tenant) and the ran the application with "Get-user" parameter. And the application is still able to get the users from AD. Not sure how secure is this thing?
Then deleted the application key from the B2c tenant application and ran the console application sample. And received an error AADSTS70002: Error validating credentials. AADSTS50012: Invalid client secret is provided.
Trace ID: cef09957-06bf-462e-a0c3-4ed6bae11e00
Correlation ID: afab126d-8694-479a-8a21-c12eb7cb176c
https://learn.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-devquickstarts-graph-dotnet
Any Idea why this is happening. I would like to implement this on a xamarin.ios app and any guidance much appreciated.
The answer to this is very similar to the answer to your other question: Exception access Azure AD B2C using ADAL library for user management, which can be summarized as:
Azure AD B2C does not yet support delegated permissions to the Azure AD or Microsoft Graph. The correct way to work around this limitation at this time is to have your native client application call a web API (using MSAL) which would in turn call the Graph API (using ADAL). This web API is an API you build which has authorization logic to scope the user management operations.
Once user management in Azure AD B2C is supported via the Microsoft Graph, you won't need this API and will be able to use delegated permissions (vs application permissions using client credentials) to have your native client application talk directly to the Microsoft Graph. In the interim, you'll have to stand up your own Web API as per the guidance above.
UPDATE: the Azure AD v2.0 endpoint and Microsoft Graph API now support client credentials flow, so you can also use MSAL for your Microsoft Graph API calls. However if you need to call the Azure AD Graph, then you will still need to use ADAL.

Resources