WebAuthenticationBroker WebAuthenticationBroker WebAuthenticationBroker WebAuthenticationBroker Class

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

Declaration

public static class WebAuthenticationBrokerpublic static class WebAuthenticationBrokerPublic Static Class WebAuthenticationBrokerpublic static class WebAuthenticationBroker

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>  

Methods summary

Starts the authentication operation with one input.

Starts the authentication operation with two inputs.

Starts the authentication operation with four inputs.

Starts the asynchronous authentication operation with two inputs. You can call this method multiple times in a single application or across multiple applications at the same time.

Starts the asynchronous authentication operation with three inputs. You can call this method multiple times in a single application or across multiple applications at the same time.

Starts the asynchronous authentication operation silently (no UI will be shown) with one input. You can call this method multiple times in a single application or across multiple applications at the same time.

Starts the asynchronous authentication operation silently (no UI will be shown) with two inputs. You can call this method multiple times in a single application or across multiple applications at the same time.

Gets the current application callback URI.

Methods

  • AuthenticateAndContinue(Uri)
    AuthenticateAndContinue(Uri)
    AuthenticateAndContinue(Uri)
    AuthenticateAndContinue(Uri)

    Starts the authentication operation with one input.

    public static void AuthenticateAndContinue(Uri requestUri)public static void AuthenticateAndContinue(Uri requestUri)Public Static Function AuthenticateAndContinue(requestUri As Uri) As voidpublic static void AuthenticateAndContinue(Uri requestUri)

    Parameters

    • requestUri

      The starting URI of the web service. This URI must be a secure address of https://.

  • AuthenticateAndContinue(Uri, Uri)
    AuthenticateAndContinue(Uri, Uri)
    AuthenticateAndContinue(Uri, Uri)
    AuthenticateAndContinue(Uri, Uri)

    Starts the authentication operation with two inputs.

    public static void AuthenticateAndContinue(Uri requestUri, Uri callbackUri)public static void AuthenticateAndContinue(Uri requestUri, Uri callbackUri)Public Static Function AuthenticateAndContinue(requestUri As Uri, callbackUri As Uri) As voidpublic static void AuthenticateAndContinue(Uri requestUri, Uri callbackUri)

    Parameters

    • requestUri

      The starting URI of the web service. This URI must be a secure address of https://.

    • callbackUri

      The callback URI that indicates the completion of the web authentication. The broker matches this URI against every URI that it is about to navigate to. The broker never navigates to this URI, instead the broker returns the control back to the application when the user clicks a link or a web server redirection is made.

  • AuthenticateAndContinue(Uri, Uri, ValueSet, WebAuthenticationOptions)
    AuthenticateAndContinue(Uri, Uri, ValueSet, WebAuthenticationOptions)
    AuthenticateAndContinue(Uri, Uri, ValueSet, WebAuthenticationOptions)
    AuthenticateAndContinue(Uri, Uri, ValueSet, WebAuthenticationOptions)

    Starts the authentication operation with four inputs.

    public static void AuthenticateAndContinue(Uri requestUri, Uri callbackUri, ValueSet continuationData, WebAuthenticationOptions options)public static void AuthenticateAndContinue(Uri requestUri, Uri callbackUri, ValueSet continuationData, WebAuthenticationOptions options)Public Static Function AuthenticateAndContinue(requestUri As Uri, callbackUri As Uri, continuationData As ValueSet, options As WebAuthenticationOptions) As voidpublic static void AuthenticateAndContinue(Uri requestUri, Uri callbackUri, ValueSet continuationData, WebAuthenticationOptions options)

    Parameters

  • AuthenticateAsync(WebAuthenticationOptions, Uri)
    AuthenticateAsync(WebAuthenticationOptions, Uri)
    AuthenticateAsync(WebAuthenticationOptions, Uri)
    AuthenticateAsync(WebAuthenticationOptions, Uri)

    Starts the asynchronous authentication operation with two inputs. You can call this method multiple times in a single application or across multiple applications at the same time.

    public static IAsyncOperation<WebAuthenticationResult> AuthenticateAsync(WebAuthenticationOptions options, Uri requestUri)public static IAsyncOperation<WebAuthenticationResult> AuthenticateAsync(WebAuthenticationOptions options, Uri requestUri)Public Static Function AuthenticateAsync(options As WebAuthenticationOptions, requestUri As Uri) As IAsyncOperation( Of WebAuthenticationResult )public static IAsyncOperation<WebAuthenticationResult> AuthenticateAsync(WebAuthenticationOptions options, Uri requestUri)

    Parameters

    Returns

    • The way to query the status and get the results of the authentication operation. If you are getting an invalid parameter error, the most common cause is that you are not using HTTPS for the requestUri parameter.

    Remarks

    There is no explicit callbackUri parameter in this method. The application's default URI is used internally as the terminator. For more information, see GetCurrentApplicationCallbackUri().

  • AuthenticateAsync(WebAuthenticationOptions, Uri, Uri)
    AuthenticateAsync(WebAuthenticationOptions, Uri, Uri)
    AuthenticateAsync(WebAuthenticationOptions, Uri, Uri)
    AuthenticateAsync(WebAuthenticationOptions, Uri, Uri)

    Starts the asynchronous authentication operation with three inputs. You can call this method multiple times in a single application or across multiple applications at the same time.

    public static IAsyncOperation<WebAuthenticationResult> AuthenticateAsync(WebAuthenticationOptions options, Uri requestUri, Uri callbackUri)public static IAsyncOperation<WebAuthenticationResult> AuthenticateAsync(WebAuthenticationOptions options, Uri requestUri, Uri callbackUri)Public Static Function AuthenticateAsync(options As WebAuthenticationOptions, requestUri As Uri, callbackUri As Uri) As IAsyncOperation( Of WebAuthenticationResult )public static IAsyncOperation<WebAuthenticationResult> AuthenticateAsync(WebAuthenticationOptions options, Uri requestUri, Uri callbackUri)

    Parameters

    • options

      The options for the authentication operation.

    • requestUri

      The starting URI of the web service. This URI must be a secure address of https://.

    • callbackUri

      The callback URI that indicates the completion of the web authentication. The broker matches this URI against every URI that it is about to navigate to. The broker never navigates to this URI, instead the broker returns the control back to the application when the user clicks a link or a web server redirection is made.

    Returns

    • The way to query the status and get the results of the authentication operation. If you are getting an invalid parameter error, the most common cause is that you are not using HTTPS for the requestUri parameter.

    Remarks

    When this method is used, no session state or persisted cookies are retained across multiple calls from the same or different Windows Store app. This method must be called on the UI thread.

  • AuthenticateSilentlyAsync(Uri)
    AuthenticateSilentlyAsync(Uri)
    AuthenticateSilentlyAsync(Uri)
    AuthenticateSilentlyAsync(Uri)

    Starts the asynchronous authentication operation silently (no UI will be shown) with one input. You can call this method multiple times in a single application or across multiple applications at the same time.

    public static IAsyncOperation<WebAuthenticationResult> AuthenticateSilentlyAsync(Uri requestUri)public static IAsyncOperation<WebAuthenticationResult> AuthenticateSilentlyAsync(Uri requestUri)Public Static Function AuthenticateSilentlyAsync(requestUri As Uri) As IAsyncOperation( Of WebAuthenticationResult )public static IAsyncOperation<WebAuthenticationResult> AuthenticateSilentlyAsync(Uri requestUri)

    Parameters

    • requestUri

      The starting URI of the web service. This URI must be a secure address of https://.

    Returns

    • The way to query the status and get the results of the authentication operation. If you are getting an invalid parameter error, the most common cause is that you are not using HTTPS for the requestUri parameter.

  • AuthenticateSilentlyAsync(Uri, WebAuthenticationOptions)
    AuthenticateSilentlyAsync(Uri, WebAuthenticationOptions)
    AuthenticateSilentlyAsync(Uri, WebAuthenticationOptions)
    AuthenticateSilentlyAsync(Uri, WebAuthenticationOptions)

    Starts the asynchronous authentication operation silently (no UI will be shown) with two inputs. You can call this method multiple times in a single application or across multiple applications at the same time.

    public static IAsyncOperation<WebAuthenticationResult> AuthenticateSilentlyAsync(Uri requestUri, WebAuthenticationOptions options)public static IAsyncOperation<WebAuthenticationResult> AuthenticateSilentlyAsync(Uri requestUri, WebAuthenticationOptions options)Public Static Function AuthenticateSilentlyAsync(requestUri As Uri, options As WebAuthenticationOptions) As IAsyncOperation( Of WebAuthenticationResult )public static IAsyncOperation<WebAuthenticationResult> AuthenticateSilentlyAsync(Uri requestUri, WebAuthenticationOptions options)

    Parameters

    Returns

    • The way to query the status and get the results of the authentication operation. If you are getting an invalid parameter error, the most common cause is that you are not using HTTPS for the requestUri parameter.

  • GetCurrentApplicationCallbackUri()
    GetCurrentApplicationCallbackUri()
    GetCurrentApplicationCallbackUri()
    GetCurrentApplicationCallbackUri()

    Gets the current application callback URI.

    public static Uri GetCurrentApplicationCallbackUri()public static Uri GetCurrentApplicationCallbackUri()Public Static Function GetCurrentApplicationCallbackUri() As Uripublic static Uri GetCurrentApplicationCallbackUri()

    Returns

    Remarks

    The current application callback URI is used as an implicit value of the callbackUri parameter of the AuthenticateAsync(WebAuthenticationOptions, Uri) method. However, applications need the URI value to add it to the request URI as required by the online provider.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Capabilities

internetClient

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.Security.Authentication.Web.dll