> ## 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.

# XGameUiShowWebAuthenticationWithOptionsAsync

> XGameUiShowWebAuthenticationWithOptionsAsync

# XGameUiShowWebAuthenticationWithOptionsAsync

Begins the asynchronous authentication request that displays a web UI, possibly full screen, that allows the user to delegate access to external web sites and services without directly providing their credentials to the running title.

## Syntax

```cpp theme={null}
STDAPI XGameUiShowWebAuthenticationWithOptionsAsync(
    _In_ XAsyncBlock* async,
    _In_ XUserHandle requestingUser,
    _In_z_ const char* requestUri,
    _In_z_ const char* completionUri,
    _In_ XGameUiWebAuthenticationOptions options
    ) noexcept;
)  
```

### Parameters

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

A pointer to the [XAsyncBlock](/reference/system/xasync/structs/xasyncblock) that is passed to [XAsyncRun](/reference/system/xasync/functions/xasyncrun).

*requestingUser*   \_In\_\
Type: XUserHandle

A handle to the user requesting the web authentication.

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

The initial URI of the web view presented to the user (likely containing fields for user authentication to the service). The request URI must be a secure HTTPS address.

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

Indicates the URI that represents successful completion of the web authentication process. When the web view is navigated to a uri that matches the *completionUri*, the web view is closed, and control is returned to the calling title.

*options* \&nbps; \_In\_
Type: [XGameUiWebAuthenticationOptions](/reference/system/xgameui/enums/xgameuiwebauthenticationoptions)

Flag indicating whether or not try and show the UI full screen or not. On PC, this flag is ignored. Full screen
is not an option that is supported on PC.

### Return value

Type: HRESULT

HRESULT success or error code of the async call.

To get the result, call [xgameuishowwebauthenticationresultsize](/reference/system/xgameui/functions/xgameuishowwebauthenticationresultsize) and [xgameuishowwebauthenticationresult](/reference/system/xgameui/functions/xgameuishowwebauthenticationresult) inside the *AsyncBlock* callback or after the *AsyncBlock* is complete.

## Remarks

When this asynchronous task runs, the system presents a web view to the user (overlaying the current application), which they can interact with or dismiss by pressing back. This allows users to use OAuth in order to grant authorization permission to external web sites and services. This can be used in scenarios such as authenticating the game to share in-game highlights on social media, requesting user data from external providers, and more.

The result of the authentication request is stored in the [XGameUiWebAuthenticationResultData](/reference/system/xgameui/structs/xgameuiwebauthenticationresultdata) object which is returned from the [XGameUiShowWebAuthenticationResult](/reference/system/xgameui/functions/xgameuishowwebauthenticationresult) method.

If the web view is closed as a result of navigating to the *completionUri*, then the *responseStatus* field of the result data structure will be `S_OK`.

If the user cancels or otherwise manually closes the web view, then the *responseStatus* field of the result data structure will be `E_CANCELLED`.

## Example

The following code example shows how to perform OAuth by using Facebook. This example does not include memory allocation error handling in order to keep the code brief.

```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(XGameUiShowWebAuthenticationWithOptionsAsync(
    block,
    currentUser,
    requestUri,
    completionUri,
    XGameUiWebAuthenticationOptions::PreferFullscreen
    ));
```

## Requirements

**Header:** XGameUI.h

**Library:** xgameruntime.lib

**Supported platforms:** Windows, XBOX One family consoles and XBOX Series consoles

## See also

[XGameUI](/reference/system/xgameui/xgameui_members)
[XGameUiShowWebAuthenticationAsync](/reference/system/xgameui/functions/xgameuishowwebauthenticationasync)\
[XGameUiShowWebAuthenticationResultSize](/reference/system/xgameui/functions/xgameuishowwebauthenticationresultsize)\
[XGameUiShowWebAuthenticationResult](/reference/system/xgameui/functions/xgameuishowwebauthenticationresult)\
[XGameUiWebAuthenticationResultData](/reference/system/xgameui/structs/xgameuiwebauthenticationresultdata)\
[Asynchronous Programming Model](/build/core-features/common/async/async-programming-model)


## Related topics

- [XGameUiWebAuthenticationOptions](/reference/system/xgameui/enums/xgameuiwebauthenticationoptions.md)
- [XGameUiShowWebAuthenticationAsync](/reference/system/xgameui/functions/xgameuishowwebauthenticationasync.md)
- [XGameUI](/reference/system/xgameui/xgameui_members.md)
- [XGameUiShowWebAuthenticationResult](/reference/system/xgameui/functions/xgameuishowwebauthenticationresult.md)
- [XGameUiShowWebAuthenticationResultSize](/reference/system/xgameui/functions/xgameuishowwebauthenticationresultsize.md)
