ASoft.BattleNet 1.0.0.12

dotnet add package ASoft.BattleNet --version 1.0.0.12
                    
NuGet\Install-Package ASoft.BattleNet -Version 1.0.0.12
                    
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="ASoft.BattleNet" Version="1.0.0.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ASoft.BattleNet" Version="1.0.0.12" />
                    
Directory.Packages.props
<PackageReference Include="ASoft.BattleNet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ASoft.BattleNet --version 1.0.0.12
                    
#r "nuget: ASoft.BattleNet, 1.0.0.12"
                    
#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.
#:package ASoft.BattleNet@1.0.0.12
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ASoft.BattleNet&version=1.0.0.12
                    
Install as a Cake Addin
#tool nuget:?package=ASoft.BattleNet&version=1.0.0.12
                    
Install as a Cake Tool

Goal of library

C# library to access Battlenet API.

Supported APIs

  • Authentication
  • Starcraft 2

Install NuGet

<PackageReference Include="ASoft.BattleNet" Version="1.0.0.*" />

Create BattleNetClient

var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();

var serviceCollection = new ServiceCollection();
serviceCollection.AddLogging();
serviceCollection.AddBattleNetClient(config);

var serviceProvider = serviceCollection.BuildServiceProvider();
var battleNetClient = serviceProvider.GetRequiredService<IBattleNetClient>();

Authentication

Battlenet supports two authentication types:

  • Partner authentication - restricted access, no user data.
  • User authentication - full access to user data.

Partner authentication

Library is designed with expectation, that it will be used by 1 partner only, therefore credentials are provided only one time during initialization as part of configuration. Credentials can be obtained from Battlenet developer portal.

Be aware - RedirectUrl MUST be registered correctly otherwise you will not be able to proceed with User authentication.

Domain "https://localhost" is accepted for local testing.

Configuration is trying to parse this model:

public class BattleNetClientOption
{
    public string ClientId? { get; set; } // cannot be null, but ```ConfigurationBuilder``` does not support immutable types yet.
    public string Secret? { get; set; } // cannot be null, but ```ConfigurationBuilder``` does not support immutable types yet.
    public Region Region { get; set; }
    public Uri RedirectUrl { get; set; }
}

User authentication

Design goal was, that application needs to process data from different users, therefore different credentials all the time. This means, that authentication needs to be done per user bases.

First, user needs to authenticate with 2FA on url below. Url will redirect user to specified redirectUrl.

https://eu.battle.net/oauth/authorize?access_type=online&client_id=<client_id>&redirect_uri=<url_encoded_redirect_url>&response_type=code&state=

Be aware:

  • Redirect url must exactly match redirect url registered in mentioned Battlenet developer portal (be aware of trailing slashes, etc.).
  • Authorization code has short validity (about 1 minute)

After obtaining authorization code through the redirect, you can get access token for given user:

var authorizationCode = "<authorization_code>";
var token = await this.battlenetClient.AuthenticateByUserCredentialsAsync(options.ClientId!, options.Secret!, authorizationCode, options.RedirectUrl).ConfigureAwait(false);

Because you don't want to force user to go throu 2FA all the time, library provides also way how to authenticate with remembered token (see below). This method is just verifying validity and storing the token in strong typed object with the expiration. Token has long validity and can be reused without bothering user to reauthenticate.

var token = await this.battlenetClient.AuthenticateByAccessTokenAsync("remebered token").ConfigureAwait(false);

How to query data

See samples below (library supports more ...).

var user = await this.battlenetClient.GetUser(token).ConfigureAwait(false);
var players = await this.battlenetClient.GetPlayers(user.Id, token).ConfigureAwait(false);
var playerIndex = 0;
var regionId = players[playerIndex].RegionId;
var realmId = players[playerIndex].RealmId;
var profileId = players[playerIndex].ProfileId;
var grandmasterLeaderboard = await this.battlenetClient.GetGrandmasterLeaderBoardAsync(regionId, token).ConfigureAwait(false);
var season = await this.battlenetClient.GetSeasonAsync(regionId, token).ConfigureAwait(false);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0.12 734 6/19/2020
1.0.0.11-prerelease 548 6/19/2020
1.0.0.10-prerelease 507 6/19/2020
1.0.0.9-prerelease 534 6/19/2020