> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XGameUiShowWebAuthenticationAsync

> XGameUiShowWebAuthenticationAsync

# XGameUiShowWebAuthenticationAsync

Web UI を表示する非同期認証要求を開始します。この UI により、ユーザーは実行中のタイトルに資格情報を直接提供することなく、外部の Web サイトやサービスへのアクセスを委任できます。

## Syntax

```cpp theme={null}
HRESULT XGameUiShowWebAuthenticationAsync(  
         XAsyncBlock* async,  
         XUserHandle requestingUser,  
         const char* requestUri,  
         const char* completionUri  
)  
```

### Parameters

*async*   \_In\_\
型: [XAsyncBlock\*](/reference/system/xasync/structs/xasyncblock)

[XAsyncRun](/reference/system/xasync/functions/xasyncrun) に渡される [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) へのポインター。

*requestingUser*   \_In\_\
型: XUserHandle

Web 認証を要求するユーザーへのハンドル。

*requestUri*   \_In\_z\_\
型: char\*

ユーザーに表示される Web ビューの初期 URI (通常、サービスに対するユーザー認証のためのフィールドを含みます)。要求 URI はセキュアな HTTPS アドレスでなければなりません。

*completionUri*   \_In\_z\_\
型: char\*

Web 認証プロセスの正常な完了を表す URI を示します。Web ビューが *completionUri* に一致する URI に遷移すると、Web ビューは閉じられ、制御は呼び出し元のタイトルに戻されます。

### Return value

型: HRESULT

非同期呼び出しの HRESULT の成功またはエラー コード。

結果を取得するには、*AsyncBlock* コールバック内、または *AsyncBlock* の完了後に [xgameuishowwebauthenticationresultsize](/reference/system/xgameui/functions/xgameuishowwebauthenticationresultsize) と [xgameuishowwebauthenticationresult](/reference/system/xgameui/functions/xgameuishowwebauthenticationresult) を呼び出します。

## Remarks

この非同期タスクが実行されると、システムはユーザーに Web ビューを (現在のアプリケーションに重ねて) 提示します。ユーザーはそれを操作するか、戻るボタンを押して閉じることができます。これにより、ユーザーは OAuth を使用して外部の Web サイトやサービスに対する認可権限を付与できます。ソーシャル メディアでゲーム内ハイライトを共有するためのゲーム認証、外部プロバイダーへのユーザー データの要求など、さまざまなシナリオで使用できます。

認証要求の結果は [XGameUiWebAuthenticationResultData](/reference/system/xgameui/structs/xgameuiwebauthenticationresultdata) オブジェクトに格納され、[XGameUiShowWebAuthenticationResult](/reference/system/xgameui/functions/xgameuishowwebauthenticationresult) メソッドから返されます。

*completionUri* への遷移の結果として Web ビューが閉じられた場合、結果データ構造体の *responseStatus* フィールドは `S_OK` になります。

ユーザーがキャンセルするか、Web ビューを手動で閉じた場合、結果データ構造体の *responseStatus* フィールドは `E_CANCELLED` になります。

## Example

次のコード例は、Facebook を使用して OAuth を実行する方法を示しています。この例では、コードを簡潔にするためにメモリ割り当てのエラー処理は含まれていません。

```cpp theme={null}
// Use Facebook example for OAuth; client_id should correspond to your registered application.
const char completionUri[] = "https://www.facebook.com/connect/login_success.html"; 
const char requestUri[] =
    "https://www.facebook.com/dialog/oauth?"
    "client_id=000000000000000&"
    "redirect_uri=https%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html&"
    "response_type=token&"
    "sdk=xboxone";

// Allocate and initialize XAsyncBlock for asynchronous authentication operation.
XAsyncBlock* block = new XAsyncBlock();
ZeroMemory(block, sizeof(XAsyncBlock));
block->callback = [](XAsyncBlock* block)
{
    // Query required size and allocate buffer for authentication result data.
    uint32_t bufferSize = 0;
    FAIL_FAST_IF_FAILED(XGameUiShowWebAuthenticationResultSize(block, &bufferSize));
    uint8_t* buffer = new uint8_t[bufferSize];

    // The currentUser is initialized with user to authenticate for.
    XGameUiWebAuthenticationResultData* resultData = nullptr;
    FAIL_FAST_IF_FAILED(XGameUiShowWebAuthenticationResult(
        block,
        bufferSize,
        buffer,
        &resultData,
        nullptr
        ));

    //
    // Use the result data here. If resultData->responseStatus is S_OK, then web authentication was successful.
    //

    // Free allocated buffer and XAsyncBlock.
    delete[] buffer;
    delete block;
};

//  Begin asynchronous authentication operation.
XUserHandle currentUser = GetCurrentUserForAuthentication();
FAIL_FAST_IF_FAILED(XGameUiShowWebAuthenticationAsync(
    block,
    currentUser,
    requestUri,
    completionUri
    ));
```

## Requirements

**ヘッダー:** XGameUI.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体および XBOX Series 本体

## See also

[XGameUI](/reference/system/xgameui/xgameui_members)
[XGameUiShowWebAuthenticationWithOptionsAsync](/reference/system/xgameui/functions/xgameuishowwebauthenticationwithoptionsasync)
[XGameUiShowWebAuthenticationResultSize](/reference/system/xgameui/functions/xgameuishowwebauthenticationresultsize)\
[XGameUiShowWebAuthenticationResult](/reference/system/xgameui/functions/xgameuishowwebauthenticationresult)\
[XGameUiWebAuthenticationResultData](/reference/system/xgameui/structs/xgameuiwebauthenticationresultdata)\
[非同期プログラミング モデル](/build/core-features/common/async/async-programming-model)


## Related topics

- [XGameUiShowWebAuthenticationResultSize](/ja-jp/reference/system/xgameui/functions/xgameuishowwebauthenticationresultsize.md)
- [XGameUiShowWebAuthenticationWithOptionsAsync](/ja-jp/reference/system/xgameui/functions/xgameuishowwebauthenticationwithoptionsasync.md)
- [XGameUiShowWebAuthenticationResult](/ja-jp/reference/system/xgameui/functions/xgameuishowwebauthenticationresult.md)
- [XGameUiWebAuthenticationResultData](/ja-jp/reference/system/xgameui/structs/xgameuiwebauthenticationresultdata.md)
- [XGameUI](/ja-jp/reference/system/xgameui/xgameui_members.md)
