UNPKG

@microsoft/teamsapp-cli

Version:

Teams Toolkit CLI is a text-based command line interface that can help scaffold, validate, and deploy applications for Microsoft Teams from the terminal or a CI/CD process.

1 lines 1.14 kB
const{OnBehalfOfUserCredential}=require("@microsoft/teamsfx"),{Client}=require("@microsoft/microsoft-graph-client"),{TokenCredentialAuthenticationProvider}=require("@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials");require("isomorphic-fetch");const oboAuthConfig={authorityHost:process.env.M365_AUTHORITY_HOST,clientId:process.env.M365_CLIENT_ID,tenantId:process.env.M365_TENANT_ID,clientSecret:process.env.M365_CLIENT_SECRET};class ProfileSsoCommandHandler{triggerPatterns="profile";async handleCommandReceived(context,message,tokenResponse){await context.sendActivity("Retrieving user information from Microsoft Graph ...");const oboCredential=new OnBehalfOfUserCredential(tokenResponse.ssoToken,oboAuthConfig),authProvider=new TokenCredentialAuthenticationProvider(oboCredential,{scopes:["User.Read"]}),graphClient=Client.initWithMiddleware({authProvider}),me=await graphClient.api("/me").get();return me?`Your command is '${message.text}' and you're logged in as ${me.displayName} (${me.userPrincipalName}).`:"Could not retrieve profile information from Microsoft Graph."}}module.exports={ProfileSsoCommandHandler};