Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Communication] - Auth - SMS live test authentication #13288

Merged
merged 7 commits into from
Jan 20, 2021
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