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

Add auth token support to WVAC #565

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
94 changes: 59 additions & 35 deletions clients/csharp-wpf/VoiceAssistantClient/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected override void OnContentRendered(EventArgs e)
// URL, a URL override. If the client doesn't meet these requirements (e.g. on first
// run), pop up the settings dialog to prompt for it.
var hasSubscriptionKey = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.SubscriptionKey);
var hasSubscriptionRegion = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.SubscriptionKeyRegion);
var hasSubscriptionRegion = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.SubscriptionRegion);
var hasUrlOverride = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.UrlOverride);

if (!hasSubscriptionKey || (!hasSubscriptionRegion && !hasUrlOverride))
Expand Down Expand Up @@ -204,89 +204,113 @@ private void InitSpeechConnector()
{
DialogServiceConfig config = null;

var hasSubscription = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.SubscriptionKey);
var hasRegion = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.SubscriptionKeyRegion);
var hasBotId = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.BotId);
var hasUrlOverride = !string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.UrlOverride);
var profile = this.settings.RuntimeSettings.Profile;
var hasSubscription = !string.IsNullOrWhiteSpace(profile.SubscriptionKey);
var hasAuthToken = !string.IsNullOrWhiteSpace(profile.AuthorizationToken);
var hasRegion = !string.IsNullOrWhiteSpace(profile.SubscriptionRegion);
var hasBotId = !string.IsNullOrWhiteSpace(profile.BotId);
var hasUrlOverride = !string.IsNullOrWhiteSpace(profile.UrlOverride);

if (hasSubscription && (hasRegion || hasUrlOverride))
if ((hasSubscription || hasAuthToken) && (hasRegion || hasUrlOverride))
{
if (!string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.CustomCommandsAppId))
if (!string.IsNullOrWhiteSpace(profile.CustomCommandsAppId))
{
// NOTE: Custom commands is a preview Azure Service.
// Set the custom commands configuration object based on three items:
// - The Custom commands application ID
// - Cognitive services speech subscription key.
// - Cognitive services speech subscription key or auth token.
// - The Azure region of the subscription key(e.g. "westus").
config = CustomCommandsConfig.FromSubscription(this.settings.RuntimeSettings.Profile.CustomCommandsAppId, this.settings.RuntimeSettings.Profile.SubscriptionKey, this.settings.RuntimeSettings.Profile.SubscriptionKeyRegion);
}
else if (hasBotId)
{
config = BotFrameworkConfig.FromSubscription(this.settings.RuntimeSettings.Profile.SubscriptionKey, this.settings.RuntimeSettings.Profile.SubscriptionKeyRegion, this.settings.RuntimeSettings.Profile.BotId);
config =
hasSubscription ? CustomCommandsConfig.FromSubscription(
profile.CustomCommandsAppId,
profile.SubscriptionKey,
profile.SubscriptionRegion)
: hasAuthToken ? CustomCommandsConfig.FromAuthorizationToken(
profile.CustomCommandsAppId,
profile.AuthorizationToken,
profile.SubscriptionRegion)
: throw new ArgumentException();
}
else
{
// Set the bot framework configuration object based on two items:
// - Cognitive services speech subscription key. It is needed for billing and is tied to the bot registration.
// - The Azure region of the subscription key(e.g. "westus").
config = BotFrameworkConfig.FromSubscription(this.settings.RuntimeSettings.Profile.SubscriptionKey, this.settings.RuntimeSettings.Profile.SubscriptionKeyRegion);
// - Cognitive services speech subscription key or auth token. This is needed for billing and is
// tied to the bot registration.
// - The Azure region of the subscription key (e.g. "westus").

config =
(hasSubscription && hasBotId) ? BotFrameworkConfig.FromSubscription(
profile.SubscriptionKey,
profile.SubscriptionRegion,
profile.BotId)
: (hasSubscription && !hasBotId) ? BotFrameworkConfig.FromSubscription(
profile.SubscriptionKey,
profile.SubscriptionRegion)
: (hasAuthToken && hasBotId) ? BotFrameworkConfig.FromAuthorizationToken(
profile.AuthorizationToken,
profile.SubscriptionRegion,
profile.BotId)
: (hasAuthToken && !hasBotId) ? BotFrameworkConfig.FromAuthorizationToken(
profile.AuthorizationToken,
profile.SubscriptionRegion)
: throw new ArgumentException();
}
}

if (!string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.ConnectionLanguage))
if (!string.IsNullOrWhiteSpace(profile.ConnectionLanguage))
{
// Set the speech recognition language. If not set, the default is "en-us".
config.Language = this.settings.RuntimeSettings.Profile.ConnectionLanguage;
config.Language = profile.ConnectionLanguage;
}

if (this.settings.RuntimeSettings.Profile.CustomSpeechEnabled)
if (profile.CustomSpeechEnabled)
{
// Set your custom speech end-point id here, as given to you by the speech portal https://speech.microsoft.com/portal.
// Otherwise the standard speech end-point will be used.
config.SetServiceProperty("cid", this.settings.RuntimeSettings.Profile.CustomSpeechEndpointId, ServicePropertyChannel.UriQueryParameter);
config.SetServiceProperty("cid", profile.CustomSpeechEndpointId, ServicePropertyChannel.UriQueryParameter);

// Custom Speech does not support cloud Keyword Verification at the moment. If this is not done, there will be an error
// from the service and connection will close. Remove line below when supported.
config.SetProperty("KeywordConfig_EnableKeywordVerification", "false");
}

if (this.settings.RuntimeSettings.Profile.VoiceDeploymentEnabled)
if (profile.VoiceDeploymentEnabled)
{
// Set one or more IDs associated with the custom TTS voice your bot will use
// The format of the string is one or more GUIDs separated by comma (no spaces). You get these GUIDs from
// your custom TTS on the speech portal https://speech.microsoft.com/portal.
config.SetProperty(PropertyId.Conversation_Custom_Voice_Deployment_Ids, this.settings.RuntimeSettings.Profile.VoiceDeploymentIds);
config.SetProperty(PropertyId.Conversation_Custom_Voice_Deployment_Ids, profile.VoiceDeploymentIds);
}

if (!string.IsNullOrEmpty(this.settings.RuntimeSettings.Profile.FromId))
if (!string.IsNullOrEmpty(profile.FromId))
{
// Set the from.id in the Bot-Framework Activity sent by this tool.
// from.id field identifies who generated the activity, and may be required by some bots.
// See https://github.com/microsoft/botframework-sdk/blob/master/specs/botframework-activity/botframework-activity.md
// for Bot Framework Activity schema and from.id.
config.SetProperty(PropertyId.Conversation_From_Id, this.settings.RuntimeSettings.Profile.FromId);
config.SetProperty(PropertyId.Conversation_From_Id, profile.FromId);
}

if (!string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.LogFilePath))
if (!string.IsNullOrWhiteSpace(profile.LogFilePath))
{
// Speech SDK has verbose logging to local file, which may be useful when reporting issues.
// Supply the path to a text file on disk here. By default no logging happens.
config.SetProperty(PropertyId.Speech_LogFilename, this.settings.RuntimeSettings.Profile.LogFilePath);
config.SetProperty(PropertyId.Speech_LogFilename, profile.LogFilePath);
}

if (hasUrlOverride)
{
// For prototyping new Direct Line Speech channel service feature, a custom service URL may be
// provided by Microsoft and entered in this tool.
config.SetProperty("SPEECH-Endpoint", this.settings.RuntimeSettings.Profile.UrlOverride);
config.SetProperty("SPEECH-Endpoint", profile.UrlOverride);
}

if (!string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.ProxyHostName) &&
!string.IsNullOrWhiteSpace(this.settings.RuntimeSettings.Profile.ProxyPortNumber) &&
int.TryParse(this.settings.RuntimeSettings.Profile.ProxyPortNumber, out var proxyPortNumber))
if (!string.IsNullOrWhiteSpace(profile.ProxyHostName) &&
!string.IsNullOrWhiteSpace(profile.ProxyPortNumber) &&
int.TryParse(profile.ProxyPortNumber, out var proxyPortNumber))
{
// To funnel network traffic via a proxy, set the host name and port number here
config.SetProxy(this.settings.RuntimeSettings.Profile.ProxyHostName, proxyPortNumber, string.Empty, string.Empty);
config.SetProxy(profile.ProxyHostName, proxyPortNumber, string.Empty, string.Empty);
}

// If a the DialogServiceConnector object already exists, destroy it first
Expand Down Expand Up @@ -317,15 +341,15 @@ private void InitSpeechConnector()
// Open a connection to Direct Line Speech channel
this.connector.ConnectAsync();

if (this.settings.RuntimeSettings.Profile.CustomSpeechEnabled)
if (profile.CustomSpeechEnabled)
{
this.customSpeechConfig = new CustomSpeechConfiguration(this.settings.RuntimeSettings.Profile.CustomSpeechEndpointId);
this.customSpeechConfig = new CustomSpeechConfiguration(profile.CustomSpeechEndpointId);
}

if (this.settings.RuntimeSettings.Profile.WakeWordEnabled)
if (profile.WakeWordEnabled)
{
// Configure wake word (also known as "keyword")
this.activeWakeWordConfig = new WakeWordConfiguration(this.settings.RuntimeSettings.Profile.WakeWordPath);
this.activeWakeWordConfig = new WakeWordConfiguration(profile.WakeWordPath);
this.connector.StartKeywordRecognitionAsync(this.activeWakeWordConfig.WakeWordModel);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ namespace VoiceAssistantClient.Settings
{
public class ConnectionProfile
{
public string SubscriptionKey { get; set; }
public string SubscriptionKey { get; set; }

public string AuthorizationToken { get; set; }

public string SubscriptionKeyRegion { get; set; }
public string SubscriptionRegion { get; set; }

public string CustomCommandsAppId { get; set; }

Expand Down
27 changes: 15 additions & 12 deletions clients/csharp-wpf/VoiceAssistantClient/SettingsDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,26 @@
<Label Grid.Row="1" Grid.Column="0" Content="Subscription key:"/>
<TextBox Grid.Row="1" Grid.Column="1" Name="SubscriptionKeyTextBox" TextBoxBase.TextChanged="SubscriptionKeyTextBox_TextChanged" Text="{Binding SubscriptionKey}"/>

<Label Grid.Row="2" Grid.Column="0" Content="Subscription key region:"/>
<TextBox Grid.Row="2" Grid.Column="1" Name='SubscriptionRegionTextBox' TextBoxBase.TextChanged="SubscriptionKeyRegionTextBox_TextChanged" Text="{Binding SubscriptionKeyRegion}"/>
<Label Grid.Row="2" Grid.Column="0" Content="Auth token:"/>
<TextBox Grid.Row="2" Grid.Column="1" Name="AuthorizationTokenTextBox" TextBoxBase.TextChanged="AuthorizationTokenTextBox_TextChanged" Text="{Binding AuthorizationToken}"/>

<Label Grid.Row="3" Grid.Column="0" Content="Custom commands app Id:"/>
<TextBox Grid.Row="3" Grid.Column="1" Name="CustomCommandsAppIdTextBox" TextBoxBase.TextChanged="CustomCommandsAppIdTextBox_TextChanged" Text="{Binding CustomCommandsAppId}"/>
<Label Grid.Row="3" Grid.Column="0" Content="Subscription key region:"/>
<TextBox Grid.Row="3" Grid.Column="1" Name='SubscriptionRegionTextBox' TextBoxBase.TextChanged="SubscriptionKeyRegionTextBox_TextChanged" Text="{Binding SubscriptionKeyRegion}"/>

<Label Grid.Row="4" Grid.Column="0" Content="Bot Id:"/>
<TextBox Grid.Row="4" Grid.Column="1" Name="BotIdTextBox" Text="{Binding BotId}"/>
<Label Grid.Row="4" Grid.Column="0" Content="Custom commands app Id:"/>
<TextBox Grid.Row="4" Grid.Column="1" Name="CustomCommandsAppIdTextBox" TextBoxBase.TextChanged="CustomCommandsAppIdTextBox_TextChanged" Text="{Binding CustomCommandsAppId}"/>

<Label Grid.Row="5" Grid.Column="0" Content="Bot Id:"/>
<TextBox Grid.Row="5" Grid.Column="1" Name="BotIdTextBox" Text="{Binding BotId}"/>

<Label Grid.Row="5" Grid.Column="0" Content="User From Id:"/>
<TextBox Grid.Row="5" Grid.Column="1" Name='FromIdTextBox' Text="{Binding FromId}"/>
<Label Grid.Row="6" Grid.Column="0" Content="User From Id:"/>
<TextBox Grid.Row="6" Grid.Column="1" Name='FromIdTextBox' Text="{Binding FromId}"/>

<Label Grid.Row="6" Grid.Column="0" Content="Language:"/>
<TextBox Grid.Row="6" Grid.Column="1" Name='LanguageTextBox' Text="{Binding ConnectionLanguage}" />
<Label Grid.Row="7" Grid.Column="0" Content="Language:"/>
<TextBox Grid.Row="7" Grid.Column="1" Name='LanguageTextBox' Text="{Binding ConnectionLanguage}" />

<Label Grid.Row="7" Grid.Column="0" Content="Log file path:"/>
<TextBox Grid.Row="7" Grid.Column="1" Name="LogFileTextBox" Text="{Binding LogFilePath}"/>
<Label Grid.Row="8" Grid.Column="0" Content="Log file path:"/>
<TextBox Grid.Row="8" Grid.Column="1" Name="LogFileTextBox" Text="{Binding LogFilePath}"/>
</Grid>

<Grid Margin="0,5,5,0">
Expand Down
Loading