Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions Project/oAuthConfig.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
const authConfig = {
auth: {
clientId: 'ENTER_CLIENT_ID',
authority: 'https://login.microsoftonline.com/ENTER_TENANT_ID'
configuration: {
auth: {
clientId: 'ENTER_CLIENT_ID',
authority: 'https://login.microsoftonline.com/common'
}
},
scopes: {
m365Login: [
"https://auth.msft.communication.azure.com/.default"
],
popUpLogin: [
"https://auth.msft.communication.azure.com/Teams.ManageCalls",
"https://auth.msft.communication.azure.com/Teams.ManageChats"
]
}
};
// Add here scopes for id token to be used at MS Identity Platform endpoints.
const authScopes = {
popUpLogin: [],
m365Login: []
};

const entraCredentialConfig = {
tenantId: 'ENTER_TENANT_ID',
clientId: 'ENTER_CLIENT_ID',
resourceEndpoint: 'ACS_RESOURCE_ENDPOINT' // e.g., 'https://contoso.unitedstates.communication.azure.com/'
};

module.exports = {authConfig, authScopes, entraCredentialConfig }
module.exports = { authConfig, entraCredentialConfig }
41 changes: 36 additions & 5 deletions Project/src/Utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '@azure/communication-common';
import { InteractiveBrowserCredential } from '@azure/identity';
import { PublicClientApplication } from "@azure/msal-browser";
import { authConfig, authScopes } from "../../oAuthConfig"
import axios from 'axios';

export const utils = {
Expand Down Expand Up @@ -64,8 +63,40 @@ export const utils = {
throw new Error('Failed to get ACS User Acccess token for the given OneSignal Registration Token');
},
teamsPopupLogin: async () => {
const oAuthObj = new PublicClientApplication(authConfig);
const popupLoginRespoonse = await oAuthObj.loginPopup({scopes: authScopes.popUpLogin});
/*
Ideally authConfig could be stored in a config file or environment variable:
const authConfig = {
configuration: {
auth: {
clientId: 'ENTER_CLIENT_ID',
authority: 'https://login.microsoftonline.com/common'
}
},
scopes: {
m365Login: [
"https://auth.msft.communication.azure.com/.default"
],
popUpLogin: [
"https://auth.msft.communication.azure.com/Teams.ManageCalls",
"https://auth.msft.communication.azure.com/Teams.ManageChats"
]
}
};
*/
const fetchAuthConfig = async () => {
const response = await axios({
url: 'authConfig',
method: 'GET'
});
if (response.status !== 200) {
throw new Error('Failed to get auth configs');
}
return response.data;
}
const authConfig = await fetchAuthConfig();

const oAuthObj = new PublicClientApplication(authConfig.configuration);
const popupLoginResponse = await oAuthObj.loginPopup({scopes: authConfig.scopes.popUpLogin});
const response = await axios({
url: 'teamsPopupLogin',
method: 'POST',
Expand All @@ -74,8 +105,8 @@ export const utils = {
'Content-type': 'application/json'
},
data: JSON.stringify({
aadToken: popupLoginRespoonse.accessToken,
userObjectId: popupLoginRespoonse.uniqueId
aadToken: popupLoginResponse.accessToken,
userObjectId: popupLoginResponse.uniqueId
})
});
if (response.status === 200) {
Expand Down
23 changes: 14 additions & 9 deletions Project/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const axios = require("axios");
const bodyParser = require('body-parser');
const msal = require('@azure/msal-node');

const {authConfig, authScopes, entraCredentialConfig} = require('./oAuthConfig');
const clientId = authConfig.auth.clientId;
const {authConfig, entraCredentialConfig} = require('./oAuthConfig');
const clientId = authConfig.configuration.auth.clientId;


if(!config || !config.connectionString || config.connectionString.indexOf('endpoint=') === -1)
Expand Down Expand Up @@ -216,11 +216,7 @@ module.exports = {
devServer.app.get('/entraConfig', async (req, res) => {
try {
res.setHeader('Content-Type', 'application/json');
res.status(200).json({
tenantId: entraCredentialConfig.tenantId,
clientId: entraCredentialConfig.clientId,
resourceEndpoint: entraCredentialConfig.resourceEndpoint
});
res.status(200).json(entraCredentialConfig);
} catch (e) {
console.error(e);
res.sendStatus(400);
Expand All @@ -231,8 +227,8 @@ module.exports = {
const email = req.body.email;
const password = req.body.password;

const pca = new msal.PublicClientApplication(authConfig);
let tokenRequest = {scopes: authScopes.m365Login}
const pca = new msal.PublicClientApplication(authConfig.configuration);
let tokenRequest = {scopes: authConfig.scopes.m365Login}

tokenRequest.username = email;
tokenRequest.password = password;
Expand All @@ -249,6 +245,15 @@ module.exports = {
res.sendStatus(400);
}
});
devServer.app.get('/authConfig', async (req, res) => {
try {
res.setHeader('Content-Type', 'application/json');
res.status(200).json(authConfig);
} catch (e) {
console.error(e);
res.sendStatus(400);
}
});
devServer.app.post('/createRoom', async (req, res) => {
try {
let participants = [];
Expand Down
Loading