Table of Contents

Class DeviceCodeAuthenticationProvider

Namespace
PnP.Core.Auth
Assembly
PnP.Core.Auth.dll

Authentication Provider that uses a device code flow for authentication

public class DeviceCodeAuthenticationProvider : OAuthAuthenticationProvider, IAuthenticationProvider
Inheritance
DeviceCodeAuthenticationProvider
Implements
Inherited Members

Constructors

DeviceCodeAuthenticationProvider(ILogger<OAuthAuthenticationProvider>, IMsalHttpClientFactory)

Public constructor leveraging DI to initialize the ILogger and IMsalHttpClientFactory interfaces

public DeviceCodeAuthenticationProvider(ILogger<OAuthAuthenticationProvider> logger, IMsalHttpClientFactory msalHttpClientFactory)

Parameters

logger ILogger<OAuthAuthenticationProvider>

The instance of the logger service provided by DI

msalHttpClientFactory IMsalHttpClientFactory

The instance of the Msal Http Client Factory service provided by DI

DeviceCodeAuthenticationProvider(string, string, PnPCoreAuthenticationDeviceCodeOptions, Action<DeviceCodeNotification>)

Public constructor for external consumers of the library

public DeviceCodeAuthenticationProvider(string clientId, string tenantId, PnPCoreAuthenticationDeviceCodeOptions options, Action<DeviceCodeNotification> deviceCodeVerification)

Parameters

clientId string

The Client ID for the Authentication Provider

tenantId string

The Tenant ID for the Authentication Provider

options PnPCoreAuthenticationDeviceCodeOptions

Options for the authentication provider

deviceCodeVerification Action<DeviceCodeNotification>

External action to manage the Device Code verification

DeviceCodeAuthenticationProvider(string, string, Uri, Action<DeviceCodeNotification>)

Public constructor for external consumers of the library

public DeviceCodeAuthenticationProvider(string clientId, string tenantId, Uri redirectUri, Action<DeviceCodeNotification> deviceCodeVerification)

Parameters

clientId string

The Client ID for the Authentication Provider

tenantId string

The Tenant ID for the Authentication Provider

redirectUri Uri

The Redirect URI for the authentication flow

deviceCodeVerification Action<DeviceCodeNotification>

External action to manage the Device Code verification

Properties

DeviceCodeVerification

Action to notify the end user about the device code request

public Action<DeviceCodeNotification> DeviceCodeVerification { get; set; }

Property Value

Action<DeviceCodeNotification>

RedirectUri

The Redirect URI for the authentication flow

public Uri RedirectUri { get; set; }

Property Value

Uri

Methods

AuthenticateRequestAsync(Uri, HttpRequestMessage)

Authenticates the specified request message.

public override Task AuthenticateRequestAsync(Uri resource, HttpRequestMessage request)

Parameters

resource Uri

Request uri

request HttpRequestMessage

The HttpRequestMessage to authenticate.

Returns

Task

The task to await.

GetAccessTokenAsync(Uri)

Gets an access token for the requested resource

public override Task<string> GetAccessTokenAsync(Uri resource)

Parameters

resource Uri

Resource to request an access token for

Returns

Task<string>

An access token

GetAccessTokenAsync(Uri, string[])

Gets an access token for the requested resource and scope

public override Task<string> GetAccessTokenAsync(Uri resource, string[] scopes)

Parameters

resource Uri

Resource to request an access token for (unused)

scopes string[]

Scopes to request

Returns

Task<string>

An access token