Skip to content

Latest commit

 

History

History
108 lines (75 loc) · 3.3 KB

README.md

File metadata and controls

108 lines (75 loc) · 3.3 KB

Xbox WebAPI library for .NET

GitHub Workflow - Build NuGet Discord

C# Xbox WebAPI, includes support for authentication with Windows Live / Xbox Live.

Usage

Basic authentication flow

using System;
using XboxWebApi.Authentication;
using XboxWebApi.Authentication.Model;

// ...

string requestUrl = AuthenticationService.GetWindowsLiveAuthenticationUrl();

/* Call requestUrl via WebWidget or manually and authenticate */

WindowsLiveResponse response = AuthenticationService.ParseWindowsLiveResponse(
    "<Received Redirection URL>");

AuthenticationService authenticator = new AuthenticationService(response);

string tokenFilePath = "tokens.json";
bool success = await authenticator.AuthenticateAsync();
if (!success)
    throw new Exception("Authentication failed!");

success = await authenticator.DumpToJsonFileAsync(tokenFilePath);
if (!success)
    throw new Exception("Failed to dump tokens");

Console.WriteLine("Tokens saved to {}", tokenFilePath);

Console.WriteLine(authenticator.XToken);
Console.WriteLine(authenticator.UserInformation);

Save token to JSON

using XboxWebApi.Authentication;

await authenticator.DumpToJsonFileAsync(tokenFilePath);

Load token from JSON

using XboxWebApi.Authentication;

AuthenticationService authenticator = await AuthenticationService.LoadFromJsonFileAsync("tokens.json");

Example Api Usage

using System;
using XboxWebApi.Common;
using XboxWebApi.Services;
using XboxWebApi.Services.Api;
using XboxWebApi.Services.Model;
using XboxWebApi.Authentication;

if (!authenticator.XToken.Valid)
{
    Console.WriteLine("Token expired, please refresh / reauthenticate");
    return;
}

XblConfiguration xblConfig = new XblConfiguration(authenticator.XToken, XblLanguage.United_States);

PresenceService presenceService = new PresenceService(xblConfig);
PeopleService peopleService = new PeopleService(xblConfig);
MessageService messageService = new MessageService(xblConfig);
// ... more services

var friends = await peopleService.GetFriendsAsync();
var presenceBatch = await presenceService.GetPresenceBatchAsync(friends.GetXuids());
for (int i = 0; i < friends.TotalCount; i++)
{
    Console.WriteLine($"{presenceBatch[i].Xuid} is {presenceBatch[i].State}");
}

Documentation

Not yet, please look at XboxWebApi.Tests for now.

Credits

Informations on endpoints gathered from:

Disclaimer

Xbox, Xbox One, Smartglass and Xbox Live are trademarks of Microsoft Corporation. Team OpenXbox is in no way endorsed by or affiliated with Microsoft Corporation, or any associated subsidiaries, logos or trademarks.