XboxAuthNet 3.0.0-beta.3

This is a prerelease version of XboxAuthNet.
There is a newer version of this package available.
See the version list below for details.
dotnet add package XboxAuthNet --version 3.0.0-beta.3
NuGet\Install-Package XboxAuthNet -Version 3.0.0-beta.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XboxAuthNet" Version="3.0.0-beta.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XboxAuthNet --version 3.0.0-beta.3
#r "nuget: XboxAuthNet, 3.0.0-beta.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install XboxAuthNet as a Cake Addin
#addin nuget:?package=XboxAuthNet&version=3.0.0-beta.3&prerelease

// Install XboxAuthNet as a Cake Tool
#tool nuget:?package=XboxAuthNet&version=3.0.0-beta.3&prerelease

XboxAuthNet

Microsoft OAuth 2.0 and Xbox Authentication

Features

Install

Install nuget package XboxAuthNet

XboxAuthNet

Usage: Microsoft OAuth

Currently only auth code flow is supported.

// Initialize API client
var httpClient = new HttpClient();
var apiClient = new MicrosoftOAuthCodeApiClient("<CLIENT-ID>", "<SCOPES>", httpClient); // replace "SCOPES" to XboxAuth.XboxScope for Xbox Authentication

// Authenticate with auth code flow
var codeFlow = new MicrosoftOAuthCodeFlowBuilder(apiClient)
    .Build();
MicrosoftOAuthResponse result = await codeFlow.Authenticate();

// `result.AccessToken` can be used on Xbox Authentication
// store `result` variable to refresh token later.
// `MicrosoftOAuthResponse` can be serialized (like json)
Console.WriteLine(result.AccessToken);
Console.WriteLine(result.RefreshToken);

Refresh Microsoft OAuth Token

if (!result.Validate())
{
    var newResult = await apiClient.RefreshToken(result.RefreshToken, CancellationToken.None);
    Console.WriteLine(newResult.AccessToken);
    Console.WriteLine(newResult.RefreshToken);
}

Usage: Xbox Authentication

There are three Xbox authentication methods. You can find a description of each method here.

Xbox Basic Authentication

var httpClient = new HttpClient();
var xboxAuthClient = new XboxAuthClient(httpClient);

var userToken = await xboxAuthClient.RequestUserToken("<microsoft_oauth2_access_token>");
var xsts = await xboxAuthClient.RequestXsts(userToken.Token, "<relying_party>");

Console.WriteLine(xsts.Token);

Xbox Full Authentication

var httpClient = new HttpClient();
var xboxAuthClient = new XboxAuthClient(httpClient);

var userToken = await xboxAuthClient.RequestSignedUserToken(new XboxSignedUserTokenRequest
{
    AccessToken = "<microsoft_oauth2_access_token>",
    TokenPrefix = AbstractXboxAuthRequest.XboxTokenPrefix
});
var deviceToken = await xboxAuthClient.RequestDeviceToken(new XboxDeviceTokenRequest
{
    DeviceType = XboxDeviceTypes.Nintendo,
    DeviceVersion = "0.0.0"
});
var titleToken = await xboxAuthClient.RequestTitleToken(new XboxTitleTokenRequest
{
    AccessToken = "<microsoft_oauth2_access_token>",
    DeviceToken = deviceToken.Token
});
var xsts = await xboxAuthClient.RequestXsts(new XboxXstsRequest
{
    UserToken = userToken.Token,
    DeviceToken = deviceToken.Token,
    TitleToken = titleToken.Token,
    RelyingParty = "<relying_party>"
});

Console.WriteLine(xsts.Token);

Xbox Sisu Authentication

var httpClient = new HttpClient();
var xboxAuthClient = new XboxAuthClient(httpClient);

var deviceToken = await xboxAuthClient.RequestDeviceToken(XboxDeviceTypes.Win32, "0.0.0");
var sisuResult = await xboxAuthClient.SisuAuth(new XboxSisuAuthRequest
{
    AccessToken = "<microsoft_oauth2_access_token>",
    ClientId = XboxGameTitles.MinecraftJava,
    DeviceToken = deviceToken.Token,
    RelyingParty = "<relying_party>"
});

Console.WriteLine(xsts.Token);

Example

Example project

References

These documents explain how Microsoft OAuth 2.0 works.

Microsoft OAuth 2.0

Desktop application calling a web api (XboxAuthNet implements interactive authentication)

This project was made possible thanks to the contributions of various open-source projects. not used any document from NDA developer program

MSAL.NET

xbox-live-api

xboxlive-auth

prismarine-auth

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net5.0-windows7.0 is compatible.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on XboxAuthNet:

Package Downloads
XboxAuthNet.Game

XboxAuthNet.Game

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.2 1,550 7/7/2023
3.0.1 139 7/7/2023
3.0.0 721 6/24/2023
3.0.0-beta.3 172 4/2/2023
3.0.0-beta.2 153 2/4/2023
3.0.0-beta.1 119 1/5/2023
2.2.0 2,386 9/7/2022
2.2.0-beta8 246 8/31/2022
2.1.0 1,455 7/29/2022
2.0.0 1,148 7/8/2022
2.0.0-beta1 135 5/29/2022
1.4.2 2,396 10/5/2021
1.4.1 612 8/22/2021
1.4.0 430 7/4/2021
1.3.0 473 12/28/2020
1.2.0 360 12/25/2020
1.1.0 391 12/14/2020
1.0.2 358 12/13/2020
1.0.1 419 12/13/2020
1.0.0 423 12/13/2020