//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenIdOfflineProvider {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Provider;
using Validation;
///
/// Interaction logic for CheckIdWindow.xaml
///
public partial class CheckIdWindow : Window {
///
/// Initializes a new instance of the class.
///
/// The base URI upon which user identity pages are created.
/// The incoming authentication request.
private CheckIdWindow(Uri userIdentityPageBase, IAuthenticationRequest request) {
Requires.NotNull(request, "request");
this.InitializeComponent();
// Initialize the window with appropriate values.
this.realmLabel.Content = request.Realm;
this.immediateModeLabel.Visibility = request.Immediate ? Visibility.Visible : Visibility.Collapsed;
this.setupModeLabel.Visibility = request.Immediate ? Visibility.Collapsed : Visibility.Visible;
if (request.IsDirectedIdentity) {
this.claimedIdentifierBox.Text = userIdentityPageBase.AbsoluteUri;
this.localIdentifierBox.Text = userIdentityPageBase.AbsoluteUri;
} else {
this.claimedIdentifierBox.Text = request.ClaimedIdentifier;
this.localIdentifierBox.Text = request.LocalIdentifier;
}
}
///
/// Processes an authentication request by a popup window.
///
/// The base URI upon which user identity pages are created.
/// The incoming authentication request.
/// The cancellation token.
///
/// A task that completes with the asynchronous operation.
///
internal static async Task ProcessAuthenticationAsync(Uri userIdentityPageBase, IAuthenticationRequest request, CancellationToken cancellationToken) {
Requires.NotNull(userIdentityPageBase, "userIdentityPageBase");
Requires.NotNull(request, "request");
var window = new CheckIdWindow(userIdentityPageBase, request);
IHostFactories hostFactories = new DefaultOpenIdHostFactories();
bool isRPDiscoverable = await request.IsReturnUrlDiscoverableAsync(hostFactories, cancellationToken) == RelyingPartyDiscoveryResult.Success;
window.discoverableYesLabel.Visibility = isRPDiscoverable ? Visibility.Visible : Visibility.Collapsed;
window.discoverableNoLabel.Visibility = isRPDiscoverable ? Visibility.Collapsed : Visibility.Visible;
bool? result = window.ShowDialog();
// If the user pressed Esc or cancel, just send a negative assertion.
if (!result.HasValue || !result.Value) {
request.IsAuthenticated = false;
return;
}
request.IsAuthenticated = window.tabControl1.SelectedItem == window.positiveTab;
if (request.IsAuthenticated.Value) {
request.ClaimedIdentifier = window.claimedIdentifierBox.Text;
request.LocalIdentifier = window.localIdentifierBox.Text;
}
}
///
/// Handles the Click event of the sendResponseButton control.
///
/// The source of the event.
/// The instance containing the event data.
private void sendResponseButton_Click(object sender, RoutedEventArgs e) {
this.DialogResult = true;
Close();
}
}
}