Skip to content

Commit c5c84a4

Browse files
committed
Added support to keep username on sign in. Might refactor later as part of the larger ISE client.
1 parent 113a146 commit c5c84a4

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

AutomationISE/AutomationISEControl.xaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
</Grid.ColumnDefinitions>
1616
<Grid.RowDefinitions>
1717
</Grid.RowDefinitions>
18-
<Button x:Name="loginButton" Content="Sign In" HorizontalAlignment="Left" Margin="10,93,0,0" VerticalAlignment="Top" Width="71" Click="loginButton_Click" Height="21"/>
18+
<Button x:Name="loginButton" Content="Sign In" HorizontalAlignment="Left" Margin="10,99,0,0" VerticalAlignment="Top" Width="71" Click="loginButton_Click" Height="21"/>
19+
<TextBox x:Name="userNameTextBox" Height="18" Margin="10,80,0,0" TextWrapping="Wrap" VerticalAlignment="Top" TextChanged="userNameTextBox_TextChanged" Grid.Column="0"/>
1920
<ComboBox x:Name="subscriptionComboBox" Margin="10,148,10,0" VerticalAlignment="Top" SelectionChanged="SubscriptionComboBox_SelectionChanged" Grid.ColumnSpan="2" Height="22"/>
2021
<ComboBox x:Name="accountsComboBox" Margin="10,204,10,0" VerticalAlignment="Top" SelectionChanged="accountsComboBox_SelectionChanged" Grid.ColumnSpan="2" Height="22"/>
2122
<TextBox x:Name="workspaceTextBox" Height="18" Margin="10,31,0,0" TextWrapping="Wrap" VerticalAlignment="Top" TextChanged="workspaceTextBox_TextChanged" Grid.Column="0"/>
2223
<Label x:Name="workspaceLabel" Content="Location to store runbooks and assets" HorizontalAlignment="Left" Margin="7,5,0,0" VerticalAlignment="Top" Width="251" Grid.ColumnSpan="2" Height="26"/>
2324
<Button x:Name="workspaceButton" Content="Browse" HorizontalAlignment="Left" Margin="5,31,0,0" VerticalAlignment="Top" Width="56" Click="workspaceButton_Click" Height="18" Grid.Column="1"/>
24-
<Label x:Name="signinLabel" Content="Sign in to Azure Automation" HorizontalAlignment="Left" Margin="7,68,0,0" VerticalAlignment="Top" Width="214" Height="26"/>
25+
<Label x:Name="signinLabel" Content="Sign in to Azure Automation" HorizontalAlignment="Left" Margin="7,55,0,0" VerticalAlignment="Top" Width="214" Height="26"/>
2526
<Label x:Name="subscriptionLabel" Content="Select Subscription" HorizontalAlignment="Left" Margin="7,126,0,0" VerticalAlignment="Top" Height="26" Width="111"/>
2627
<Label x:Name="automationAccountLabel" Content="Select Automation Account" HorizontalAlignment="Left" Margin="7,181,0,0" VerticalAlignment="Top" Height="26" Width="154"/>
2728
<TextBox x:Name="configurationStatusTextBox" Grid.ColumnSpan="2" Height="278" Margin="10,271,10,0" TextWrapping="Wrap" VerticalAlignment="Top" BorderThickness="2" TextChanged="configurationStatusTextBox_TextChanged"/>

AutomationISE/AutomationISEControl.xaml.cs

+14-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public AutomationISEControl()
5050
}
5151
workspaceTextBox.Text = localWorkspace;
5252

53+
userNameTextBox.Text = Properties.Settings.Default["ADUserName"].ToString();
54+
5355
assetsComboBox.Items.Add(Constants.assetVariable);
5456
}
5557
catch (Exception exception)
@@ -68,11 +70,15 @@ private async void loginButton_Click(object sender, RoutedEventArgs e)
6870
{
6971
try {
7072

71-
Properties.Settings.Default["localWorkspace"] = workspaceTextBox.Text;
72-
Properties.Settings.Default.Save();
7373

7474
UpdateStatusBox(configurationStatusTextBox, "Launching login window to sign in");
75-
AuthenticationResult ADToken = AuthenticateHelper.GetInteractiveLogin();
75+
String UserName = userNameTextBox.Text;
76+
AuthenticationResult ADToken = AuthenticateHelper.GetInteractiveLogin(UserName);
77+
78+
Properties.Settings.Default["localWorkspace"] = workspaceTextBox.Text;
79+
Properties.Settings.Default["ADUserName"] = ADToken.UserInfo.DisplayableId;
80+
userNameTextBox.Text = ADToken.UserInfo.DisplayableId;
81+
Properties.Settings.Default.Save();
7682

7783
subscriptionClient = new AutomationAzure.AutomationSubscription(ADToken, workspaceTextBox.Text);
7884

@@ -231,5 +237,10 @@ private void TabControl_SelectionChanged(object sender, SelectionChangedEventArg
231237
return;
232238
}
233239
}
240+
241+
private void userNameTextBox_TextChanged(object sender, TextChangedEventArgs e)
242+
{
243+
244+
}
234245
}
235246
}

AutomationISE/Model/AuthenticateHelper.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ public static async Task<AuthenticationResult> GetAuthorizationHeader(String Use
3838
return await AuthContext.AcquireTokenAsync(Constants.appIdURI, Constants.clientID, Creds);
3939
}
4040

41-
public static AuthenticationResult GetInteractiveLogin()
41+
public static AuthenticationResult GetInteractiveLogin(String Username = null)
4242
{
4343
var ctx = new AuthenticationContext(string.Format(Constants.authority, Constants.tenant));
44-
return ctx.AcquireToken(Constants.appIdURI, Constants.clientID, new Uri(Constants.redirectURI), PromptBehavior.Always);
4544

45+
if (Username != null)
46+
{
47+
UserIdentifier user = new UserIdentifier(Username, UserIdentifierType.RequiredDisplayableId);
48+
return ctx.AcquireToken(Constants.appIdURI, Constants.clientID, new Uri(Constants.redirectURI), PromptBehavior.Always, user);
49+
}
50+
else return ctx.AcquireToken(Constants.appIdURI, Constants.clientID, new Uri(Constants.redirectURI), PromptBehavior.Always);
4651
}
4752
}
4853
}

0 commit comments

Comments
 (0)