Skip to content

Commit

Permalink
[Communication] - Auth - SMS live test authentication (#13288)
Browse files Browse the repository at this point in the history
* [smsClientWithToken.spec] remove COMMUNICATION_ENDPOINT and replace by parsing connection string
* [recording] adding new recordings node and browser
* [smsClientWithToken] using parseConnectionString instead of own function
* [connectionString] adding missing documentation
  • Loading branch information
JoshuaLai authored Jan 20, 2021
1 parent b855292 commit 99135cc
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export const createCommunicationAuthPolicy: (credential: KeyCredential | TokenCr
// @internal
export const _deserializeCommunicationIdentifier: (serializedIdentifier: _SerializedCommunicationIdentifier) => CommunicationIdentifierKind;

// @public
export interface EndpointCredential {
credential: KeyCredential;
endpoint: string;
}

// @public
export const getIdentifierKind: (identifier: CommunicationIdentifier) => CommunicationIdentifierKind;

Expand Down Expand Up @@ -101,6 +107,9 @@ export interface MicrosoftTeamsUserKind extends MicrosoftTeamsUserIdentifier {
// @public
export const parseClientArguments: (connectionStringOrUrl: string, credentialOrOptions?: any) => UrlWithCredential;

// @public
export const parseConnectionString: (connectionString: string) => EndpointCredential;

// @public
export interface PhoneNumberIdentifier {
phoneNumber: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
// Licensed under the MIT license.

import { AzureKeyCredential, KeyCredential } from "@azure/core-auth";

/**
* Represents different properties of connection string
* using format "/endpoint=(.*);accesskey=(.*)"
*/
export interface EndpointCredential {
/**
* The endpoint as string
*/
endpoint: string;
/**
* The access key represented as a KeyCredential object
*/
credential: KeyCredential;
}

Expand All @@ -18,7 +27,12 @@ const tryParseConnectionString = (s: string): EndpointCredential | undefined =>
}
return undefined;
};

/**
* Returns an EndpointCredential to easily access properties of the connection string
*
* @param {string} connectionString The connection string to parse
* @returns {EndpointCredential} Object to access the endpoint and the credenials
*/
export const parseConnectionString = (connectionString: string): EndpointCredential => {
const parsedConnectionString = tryParseConnectionString(connectionString);
if (parsedConnectionString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
export * from "./communicationAccessKeyCredentialPolicy";
export * from "./communicationAuthPolicy";
export * from "./clientArguments";
export * from "./connectionString";
1 change: 0 additions & 1 deletion sdk/communication/communication-sms/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ module.exports = function(config) {
"AZURE_COMMUNICATION_LIVETEST_CONNECTION_STRING",
"AZURE_PHONE_NUMBER",
"TEST_MODE",
"COMMUNICATION_ENDPOINT",
"AZURE_CLIENT_ID",
"AZURE_CLIENT_SECRET",
"AZURE_TENANT_ID"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SendRequest, SmsClient } from "../src/smsClient";
import { assert } from "chai";
import { isNode } from "@azure/core-http";
import * as dotenv from "dotenv";
import { parseConnectionString } from "@azure/communication-common";
import { createCredential, recorderConfiguration } from "./utils/recordedClient";

if (isNode) {
Expand All @@ -32,7 +33,8 @@ describe("SmsClientWithToken [Playback/Live]", async () => {
this.skip();
}

const endpoint = env.COMMUNICATION_ENDPOINT;
const endpoint = parseConnectionString(env.AZURE_COMMUNICATION_LIVETEST_CONNECTION_STRING)
.endpoint;
const fromNumber = env.AZURE_PHONE_NUMBER;
const toNumber = env.AZURE_PHONE_NUMBER;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const recorderConfiguration: RecorderEnvironmentSetup = {
replaceableVariables: {
AZURE_COMMUNICATION_LIVETEST_CONNECTION_STRING: "endpoint=https://endpoint/;accesskey=banana",
AZURE_PHONE_NUMBER: "+18005551234",
COMMUNICATION_ENDPOINT: "https://endpoint/",
AZURE_CLIENT_ID: "SomeClientId",
AZURE_CLIENT_SECRET: "SomeClientSecret",
AZURE_TENANT_ID: "SomeTenantId"
Expand Down

0 comments on commit 99135cc

Please sign in to comment.