WebAuthenticationBroker 類別

定義

啟動驗證作業。 您可以在單一應用程式中或同時跨多個應用程式多次呼叫這個類別的方法。 範例庫中的 Web 驗證代理程式範例 是如何使用 WebAuthenticationBroker 類別進行單一登入 (SSO) 連線的範例。

public ref class WebAuthenticationBroker abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class WebAuthenticationBroker final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public static class WebAuthenticationBroker
Public Class WebAuthenticationBroker
繼承
Object Platform::Object IInspectable WebAuthenticationBroker
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)
應用程式功能
internetClient

範例

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>  

備註

此類別的所有成員都是靜態的。 您可以存取它們,而不需建立物件。 若要針對使用此類別時的問題進行疑難排解,請參閱事件記錄檔。 若要檢視事件記錄檔,請啟動 Eventvwr.exe,然後流覽至 [應用程式和服務記錄 > ][Microsoft > Windows > WebAuth > 操作]。

方法

AuthenticateAndContinue(Uri)

使用一個輸入啟動驗證作業。

AuthenticateAndContinue(Uri, Uri)

使用兩個輸入啟動驗證作業。

AuthenticateAndContinue(Uri, Uri, ValueSet, WebAuthenticationOptions)

使用四個輸入啟動驗證作業。

AuthenticateAsync(WebAuthenticationOptions, Uri)

使用兩個輸入啟動非同步驗證作業。 您可以在單一應用程式中多次呼叫此方法,或同時跨多個應用程式呼叫此方法。

AuthenticateAsync(WebAuthenticationOptions, Uri, Uri)

使用三個輸入啟動非同步驗證作業。 您可以在單一應用程式中多次呼叫此方法,或同時跨多個應用程式呼叫此方法。

AuthenticateSilentlyAsync(Uri)

以無訊息方式啟動非同步驗證作業, (不會顯示具有一個輸入的 UI) 。 您可以在單一應用程式中多次呼叫此方法,或同時跨多個應用程式呼叫此方法。

AuthenticateSilentlyAsync(Uri, WebAuthenticationOptions)

以無訊息方式啟動非同步驗證作業, (不會顯示具有兩個輸入的 UI) 。 您可以在單一應用程式中多次呼叫此方法,或同時跨多個應用程式呼叫此方法。

GetCurrentApplicationCallbackUri()

取得目前的應用程式回呼 URI。

適用於

另請參閱