Skip to content

Conversation

Harikrishnan-MSFT
Copy link
Contributor

…account in Teams tab

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR creates a new C# sample demonstrating Microsoft Entra ID authentication and account switching within Microsoft Teams tabs. The sample shows how users can sign in with different Entra accounts for secure, flexible access across Teams, Outlook, and Office platforms.

Key Changes

  • Complete ASP.NET Core 6.0 web application with MVC architecture
  • OAuth 2.0 authorization code flow implementation for Microsoft Entra ID
  • Teams-specific authentication using Teams JavaScript SDK v2.34.0
  • Cross-platform support for Teams, Outlook, and Microsoft Office

Reviewed Changes

Copilot reviewed 29 out of 44 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
assets/sample.json Sample metadata configuration with Teams-specific properties
TabAuthEntraAccount/*.cs Core ASP.NET application files including controllers, models, and startup configuration
Views/**/*.cshtml MVC views for authentication flow and user interface
M365Agent/** Teams Toolkit configuration for deployment and manifest
README.md Comprehensive documentation with setup instructions and authentication flow
.github/workflows/build-complete-samples.yml CI/CD integration for automated builds

Comment on lines 36 to 70
</script>
@{
ViewBag.Title = "title";
Layout = "_Layout";
}

<script src="https://res.cdn.office.net/teams-js/2.34.0/js/MicrosoftTeams.min.js"
integrity="sha384-brW9AazbKR2dYw2DucGgWCCcmrm2oBFV4HQidyuyZRI/TnAkmOOnTARSTdps3Hwt"
crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
getAuthToken();
});

// Get id token.
function getAuthToken() {
const params = new URLSearchParams(window.location.search);
const result = params.get('code');
const { authId, method, hostRedirectUrl } = JSON.parse(params.get('state'));
const baseUrl = hostRedirectUrl.split('authId')[0];
if (method === 'deeplink') {
window.location.href = `${baseUrl}authId=${authId}&result=${result}`
} else {
microsoftTeams.app.initialize().then(() => {
if (result) {
microsoftTeams.authentication.notifySuccess(result);
} else {
const error = params.get('error') || 'OAuth failed';
microsoftTeams.authentication.notifyFailure(error);
}
});
}
}
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire Razor view content and script block are duplicated starting from line 37. This creates duplicate function definitions and DOM ready handlers, which could cause unexpected behavior and makes the code harder to maintain.

Suggested change
</script>
@{
ViewBag.Title = "title";
Layout = "_Layout";
}
<script src="https://res.cdn.office.net/teams-js/2.34.0/js/MicrosoftTeams.min.js"
integrity="sha384-brW9AazbKR2dYw2DucGgWCCcmrm2oBFV4HQidyuyZRI/TnAkmOOnTARSTdps3Hwt"
crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
getAuthToken();
});
// Get id token.
function getAuthToken() {
const params = new URLSearchParams(window.location.search);
const result = params.get('code');
const { authId, method, hostRedirectUrl } = JSON.parse(params.get('state'));
const baseUrl = hostRedirectUrl.split('authId')[0];
if (method === 'deeplink') {
window.location.href = `${baseUrl}authId=${authId}&result=${result}`
} else {
microsoftTeams.app.initialize().then(() => {
if (result) {
microsoftTeams.authentication.notifySuccess(result);
} else {
const error = params.get('error') || 'OAuth failed';
microsoftTeams.authentication.notifyFailure(error);
}
});
}
}

Copilot uses AI. Check for mistakes.

getAuthToken();
});

// Get google client side token.
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment mentions 'google client side token' but this is a Microsoft Entra ID authentication implementation. The comment should reference Microsoft or Entra ID instead of Google.

Suggested change
// Get google client side token.
// Get Microsoft Entra ID client side token.

Copilot uses AI. Check for mistakes.

getAuthToken();
});

// Get id token.
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an extra space in the comment 'Get id token.' It should be 'Get id token.' or more descriptively 'Get ID token.'

Suggested change
// Get id token.
// Get id token.

Copilot uses AI. Check for mistakes.

"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The appsettings.json file contains empty placeholders for sensitive configuration values (ClientId, ClientSecret, RedirectUri) that will be committed to source control. Consider using appsettings.Development.json or environment variables for these values, and add a comment indicating these are placeholder values that must be configured.

Copilot uses AI. Check for mistakes.

{
try
{
var client = new HttpClient();
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new HttpClient instance directly can lead to socket exhaustion issues. The class already has IHttpClientFactory injected but it's not being used. Consider using _httpClientFactory.CreateClient() instead of new HttpClient().

Suggested change
var client = new HttpClient();
var client = _httpClientFactory.CreateClient();

Copilot uses AI. Check for mistakes.

var accessToken = doc.RootElement.GetProperty("access_token").GetString();

// Call Microsoft Graph
var graphClient = new HttpClient();
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new HttpClient instance directly can lead to socket exhaustion issues. Consider using _httpClientFactory.CreateClient() for this Graph API client as well.

Copilot uses AI. Check for mistakes.

@Harikrishnan-MSFT
Copy link
Contributor Author

Copy link
Collaborator

@Pawank-MSFT Pawank-MSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks correct, Approving!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants