Skip to content

Commit

Permalink
Merge pull request #55 from Azure-Samples/add-arm-template-for-deploy…
Browse files Browse the repository at this point in the history
…ment

Implement the arm template custom deployment approach
  • Loading branch information
clarenceli-msft authored Jan 25, 2022
2 parents f3a97e2 + 31117f6 commit a3e07dc
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 42 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ jobs:
# Build everything
npm install
npm run build
7z a -tzip -r "auth-sample.zip" ./build/*
# Delete output directory
# rm -r "./build"
7z a -tzip -r "auth-sample.zip" ./*
- name: Publish
uses: softprops/action-gh-release@v1
Expand Down
8 changes: 4 additions & 4 deletions deploy/azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
"displayName": "appSettings"
},
"properties": {
"communicationServices_connectionString": "[listkeys(variables('commsName'), '2020-08-20-preview' ).primaryConnectionString]",
"azureActiveDirectory_clientId": "",
"azureActiveDirectory_clientSecret": "",
"azureActiveDirectory_tenantId": ""
"communicationServices__connectionString": "[listkeys(variables('commsName'), '2020-08-20-preview' ).primaryConnectionString]",
"azureActiveDirectory__clientId": "",
"azureActiveDirectory__clientSecret": "",
"azureActiveDirectory__tenantId": ""
}
},
{
Expand Down
15 changes: 15 additions & 0 deletions src/appSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"communicationServices": {
"connectionString": "<your_acs_resource_connection_string>",
"scopes": ["voip", "chat"]
},
"azureActiveDirectory": {
"instance": "https://login.microsoftonline.com/",
"clientId": "<your_server_app_client_id>",
"clientSecret": "<your_server_app_client_secret>",
"tenantId": "<your_server_app_tenant_id>"
},
"graph": {
"extensionName": "com.contoso.identityMapping"
}
}
24 changes: 0 additions & 24 deletions src/appSettings.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/services/aadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*---------------------------------------------------------------------------------------------*/

import { Configuration, ConfidentialClientApplication } from '@azure/msal-node';
import { appSettings } from '../appSettings';
import * as appSettings from '../appSettings.json';

// Error messages
const EXCHANGE_AAD_TOKEN_VIA_OBO_ERROR =
Expand Down
14 changes: 7 additions & 7 deletions src/services/acsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { CommunicationUserIdentifier } from '@azure/communication-common';
import {
CommunicationAccessToken,
CommunicationIdentityClient,
CommunicationUserToken
CommunicationUserToken,
TokenScope
} from '@azure/communication-identity';
import { appSettings } from '../appSettings';
import * as appSettings from '../appSettings.json';

// Error messages
const CREATE_ACS_USER_IDENTITY_ERROR = 'An error occured when creating an ACS user id';
Expand All @@ -19,6 +20,8 @@ const CREATE_ACS_USER_IDENTITY_TOKEN_ERROR =
const DELETE_ACS_USER_IDENTITY_ERROR = 'An error occured when deleting an ACS user id';
const EXCHANGE_AAD_TOKEN_ERROR = 'An error occured when exchanging an AAD token';

const communicationServicesScopes = appSettings.communicationServices.scopes.map((item) => item as TokenScope);

/**
* Instantiate the identity client using the connection string.
*
Expand Down Expand Up @@ -56,10 +59,7 @@ export const createACSToken = async (acsUserId: string): Promise<CommunicationAc
try {
// Issue an access token with the given scopes for an identity
const communicationUserIdentifierObject: CommunicationUserIdentifier = { communicationUserId: acsUserId };
const tokenResponse = await identityClient.getToken(
communicationUserIdentifierObject,
appSettings.communicationServices.scopes
);
const tokenResponse = await identityClient.getToken(communicationUserIdentifierObject, communicationServicesScopes);

return tokenResponse;
} catch (error) {
Expand Down Expand Up @@ -96,7 +96,7 @@ export const createACSUserIdentityAndToken = async (): Promise<CommunicationUser
const identityClient = createAuthenticatedClient();
try {
// Issue an identity and an access token with the given scopes for the new identity
const identityTokenResponse = await identityClient.createUserAndToken(appSettings.communicationServices.scopes);
const identityTokenResponse = await identityClient.createUserAndToken(communicationServicesScopes);

return identityTokenResponse;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/graphService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Used to fix the error "PolyFillNotAvailable: Library cannot function without fetch. So, please provide polyfill for it."
import 'isomorphic-fetch';
import { Client } from '@microsoft/microsoft-graph-client';
import { appSettings } from '../appSettings';
import * as appSettings from '../appSettings.json';

// Error messages
const RETRIEVE_IDENTITY_MAPPING_ERROR = 'An error occured when retrieving the identity mapping information';
Expand Down
2 changes: 1 addition & 1 deletion tests/services/graphService/getACSUserId.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// <reference path="../../../node_modules/@types/jest/index.d.ts" />

import { Client, GraphRequest } from '@microsoft/microsoft-graph-client';
import { appSettings } from '../../../src/appSettings';
import * as appSettings from '../../../src/appSettings.json';
import * as graphService from '../../../src/services/graphService';
import { mockCommunicationAccessToken, mockAcsUserId } from '../../utils/mockData';

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"moduleResolution": "node",
"sourceMap": true,
"outDir": "build",
"baseUrl": "."
"baseUrl": ".",
"resolveJsonModule": true
},
"include": ["src/**/*"]
}

0 comments on commit a3e07dc

Please sign in to comment.