Show / Hide Table of Contents

Getting Started

Installation

Add the NuGet feed (click "Connect to Feed" for instructions) and install the required Microsoft.XboxStudios.SQTech.Authentication.* packages:

  • Abstractions: Provides interfaces to acquire and cache tokens.
  • PublicClientApp: Provides an implementation of the authorization code flow to acquire tokens for public clients.
  • FileCache: Provides a cross platform implementation to cache authorization tokens to file. This is only recommended for desktop or console applications.

Interfaces

IAuthTokenProvider is used to acquire a token for specific application scopes. Then the access token can be used in an HTTP authentication header before making the request. Example:

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct)
{
    var scopes = new string[] { "User.Read" };
    var accessToken = await this.authTokenProvider.AcquireTokenAsync(scopes, ct);
    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken)
    return await base.SendAsync(request, ct);
}

Public Client Application Auth Provider

The public client application auth provider attempts to acquire a token silently first. If unsuccessful, an interactive login is presented to the user.

To register the authentication provider, add a dependency to Microsoft.XboxStudios.SQTech.Authentication.PublicClientApp NuGet package and use one of the service collection extension methods provided. Example:

services.AddMicrosoftPublicClientAppAuth(clientId: "TODO: Enter Azure app registration client ID");

File Token Cache

To avoid prompting the user to authenticate interactively frequently, a file token cache may be utilized. The file token cache uses the cross platform solution offered by MSAL public client application extensions.

To register the file token cache, add a dependency to Microsoft.XboxStudios.SQTech.Authentication.FileCache and add it to the service collection as such:

services.AddFileTokenCache();

If required, provide CacheSettings to the method to configure where the auth tokens are cached on the file system.

Note the file token cache is only recommended for desktop or console applications.


This page was last modified on February 14 2023, 07:11 PM (UTC).

  • Improve this Doc
In This Article
Back to top Generated by DocFX