Skip to content

Commit

Permalink
Added support to keep username on sign in. Might refactor later as pa…
Browse files Browse the repository at this point in the history
…rt of the larger ISE client.
  • Loading branch information
eamonoreilly committed Jun 30, 2015
1 parent 113a146 commit c5c84a4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
5 changes: 3 additions & 2 deletions AutomationISE/AutomationISEControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
</Grid.RowDefinitions>
<Button x:Name="loginButton" Content="Sign In" HorizontalAlignment="Left" Margin="10,93,0,0" VerticalAlignment="Top" Width="71" Click="loginButton_Click" Height="21"/>
<Button x:Name="loginButton" Content="Sign In" HorizontalAlignment="Left" Margin="10,99,0,0" VerticalAlignment="Top" Width="71" Click="loginButton_Click" Height="21"/>
<TextBox x:Name="userNameTextBox" Height="18" Margin="10,80,0,0" TextWrapping="Wrap" VerticalAlignment="Top" TextChanged="userNameTextBox_TextChanged" Grid.Column="0"/>
<ComboBox x:Name="subscriptionComboBox" Margin="10,148,10,0" VerticalAlignment="Top" SelectionChanged="SubscriptionComboBox_SelectionChanged" Grid.ColumnSpan="2" Height="22"/>
<ComboBox x:Name="accountsComboBox" Margin="10,204,10,0" VerticalAlignment="Top" SelectionChanged="accountsComboBox_SelectionChanged" Grid.ColumnSpan="2" Height="22"/>
<TextBox x:Name="workspaceTextBox" Height="18" Margin="10,31,0,0" TextWrapping="Wrap" VerticalAlignment="Top" TextChanged="workspaceTextBox_TextChanged" Grid.Column="0"/>
<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"/>
<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"/>
<Label x:Name="signinLabel" Content="Sign in to Azure Automation" HorizontalAlignment="Left" Margin="7,68,0,0" VerticalAlignment="Top" Width="214" Height="26"/>
<Label x:Name="signinLabel" Content="Sign in to Azure Automation" HorizontalAlignment="Left" Margin="7,55,0,0" VerticalAlignment="Top" Width="214" Height="26"/>
<Label x:Name="subscriptionLabel" Content="Select Subscription" HorizontalAlignment="Left" Margin="7,126,0,0" VerticalAlignment="Top" Height="26" Width="111"/>
<Label x:Name="automationAccountLabel" Content="Select Automation Account" HorizontalAlignment="Left" Margin="7,181,0,0" VerticalAlignment="Top" Height="26" Width="154"/>
<TextBox x:Name="configurationStatusTextBox" Grid.ColumnSpan="2" Height="278" Margin="10,271,10,0" TextWrapping="Wrap" VerticalAlignment="Top" BorderThickness="2" TextChanged="configurationStatusTextBox_TextChanged"/>
Expand Down
17 changes: 14 additions & 3 deletions AutomationISE/AutomationISEControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public AutomationISEControl()
}
workspaceTextBox.Text = localWorkspace;

userNameTextBox.Text = Properties.Settings.Default["ADUserName"].ToString();

assetsComboBox.Items.Add(Constants.assetVariable);
}
catch (Exception exception)
Expand All @@ -68,11 +70,15 @@ private async void loginButton_Click(object sender, RoutedEventArgs e)
{
try {

Properties.Settings.Default["localWorkspace"] = workspaceTextBox.Text;
Properties.Settings.Default.Save();

UpdateStatusBox(configurationStatusTextBox, "Launching login window to sign in");
AuthenticationResult ADToken = AuthenticateHelper.GetInteractiveLogin();
String UserName = userNameTextBox.Text;
AuthenticationResult ADToken = AuthenticateHelper.GetInteractiveLogin(UserName);

Properties.Settings.Default["localWorkspace"] = workspaceTextBox.Text;
Properties.Settings.Default["ADUserName"] = ADToken.UserInfo.DisplayableId;
userNameTextBox.Text = ADToken.UserInfo.DisplayableId;
Properties.Settings.Default.Save();

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

Expand Down Expand Up @@ -231,5 +237,10 @@ private void TabControl_SelectionChanged(object sender, SelectionChangedEventArg
return;
}
}

private void userNameTextBox_TextChanged(object sender, TextChangedEventArgs e)
{

}
}
}
9 changes: 7 additions & 2 deletions AutomationISE/Model/AuthenticateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ public static async Task<AuthenticationResult> GetAuthorizationHeader(String Use
return await AuthContext.AcquireTokenAsync(Constants.appIdURI, Constants.clientID, Creds);
}

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

if (Username != null)
{
UserIdentifier user = new UserIdentifier(Username, UserIdentifierType.RequiredDisplayableId);
return ctx.AcquireToken(Constants.appIdURI, Constants.clientID, new Uri(Constants.redirectURI), PromptBehavior.Always, user);
}
else return ctx.AcquireToken(Constants.appIdURI, Constants.clientID, new Uri(Constants.redirectURI), PromptBehavior.Always);
}
}
}

0 comments on commit c5c84a4

Please sign in to comment.