WebAuthenticationBroker class

Applies to Windows and Windows Phone

Starts the authentication operation. You can call the methods of this class multiple times in a single application or across multiple applications at the same time.

The Web authentication broker sample in the Samples gallery is an example of how to use the WebAuthenticationBroker class for single sign on (SSO) connections.

Syntax


var webAuthenticationBroker = Windows.Security.Authentication.Web.WebAuthenticationBroker;

Attributes

[Threading(Both)]
[Version(0x06020000)]

Members

The WebAuthenticationBroker class has these types of members:

Methods

The WebAuthenticationBroker class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
AuthenticateAndContinue(Uri) Starts the authentication operation with one input.
AuthenticateAndContinue(Uri, Uri) Starts the authentication operation with two inputs.
AuthenticateAndContinue(Uri, Uri, ValueSet, WebAuthenticationOptions) Starts the authentication operation with four inputs.
AuthenticateAsync(WebAuthenticationOptions, Uri) Starts the asynchronous authentication operation with two inputs.
AuthenticateAsync(WebAuthenticationOptions, Uri, Uri) Starts the asynchronous authentication operation with three inputs.
AuthenticateSilentlyAsync(Uri) Starts the asynchronous authentication operation silently (no UI will be shown) with one input.
AuthenticateSilentlyAsync(Uri, WebAuthenticationOptions) Starts the asynchronous authentication operation silently (no UI will be shown) with two inputs.
GetCurrentApplicationCallbackUri Gets the current application callback URI.

 

Remarks

All members of this class are static. You can access them without creating an object. To troubleshoot issues when using this class, see the event log. To view the event log, start Eventvwr.exe, and navigate to Application and Services Logs > Microsoft > Windows > WebAuth > Operational.

Examples


private void OutputToken(String TokenUri)
{
   Page outputFrame = (Page)rootPage.OutputFrame.Content;
   TextBox FacebookReturnedToken = outputFrame.FindName("FacebookReturnedToken") as TextBox;
   FacebookReturnedToken.Text = TokenUri;
}


try
{
    String FacebookURL = "https://www.facebook.com/dialog/oauth?client_id=" + FacebookClientID.Text + "&redirect_uri=" + Uri.EscapeUriString(FacebookCallbackUrl.Text) + "&scope=read_stream&display=popup&response_type=token";

    System.Uri StartUri = new Uri(FacebookURL);
    System.Uri EndUri = new Uri(FacebookCallbackUrl.Text);

    WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
                                            WebAuthenticationOptions.None,
                                            StartUri,
                                            EndUri);
    if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
    {
        OutputToken(WebAuthenticationResult.ResponseData.ToString());
    }
    else if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
    {
        OutputToken("HTTP Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseErrorDetail.ToString());
    }
    else
    {
        OutputToken("Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseStatus.ToString());
    }
}
catch (Exception Error)
{
    //
    // Bad Parameter, SSL/TLS Errors and Network Unavailable errors are to be handled here.
    //
}



            <TextBlock x:Name="InputTextBlock1"  TextWrapping="Wrap" Grid.Row="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" > 
                Connect to Facebook using the OAuth 2.0 protocol for authentication and authorization. 
            </TextBlock> 
            <StackPanel Orientation="Vertical" Margin="0,10,0,0" Grid.Row="1"> 
                <StackPanel Orientation="Horizontal"> 
                    <TextBlock TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" Text="App ID   : " VerticalAlignment="Bottom"/> 
                    <TextBox x:Name="FacebookClientID" Height="14" Width="173" Text=""/> 
                </StackPanel> 
                <StackPanel Orientation="Horizontal"> 
                    <TextBlock TextWrapping="Wrap" Style="{StaticResource BasicTextStyle}" Text="Site URL : " VerticalAlignment="Bottom"/> 
                    <TextBox x:Name="FacebookCallbackUrl" Height="14" Width="433" Text=""/> 
                </StackPanel> 
                <StackPanel Orientation="Vertical" Margin="0,10,0,0"> 
                    <Button x:Name="Launch" Content="Launch" Margin="0,0,10,0" Click="Launch_Click"/> 
                </StackPanel> 
            </StackPanel>  


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Security.Authentication.Web
Windows::Security::Authentication::Web [C++]

Metadata

Windows.winmd

Capabilities

internetClient

See also

Authentication and user identity (JavaScript)
Authentication and user identity (C#/C++/VB)
Quickstart: Connecting to an online identity provider (JavaScript)
Quickstart: Connecting to an online identity provider (C#/C++/VB)
Windows authentication broker sample

 

 

Show:
© 2014 Microsoft