Table of Contents

Class UsernamePasswordAuthenticationProvider

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

Authentication Provider that uses a Resource Owner Password Credentials (ROCP) credential flow

public sealed class UsernamePasswordAuthenticationProvider : OAuthAuthenticationProvider, IAuthenticationProvider
Inheritance
UsernamePasswordAuthenticationProvider
Implements
Inherited Members

Remarks

Constructors

UsernamePasswordAuthenticationProvider(ILogger<OAuthAuthenticationProvider>, IMsalHttpClientFactory)

Public constructor leveraging DI to initialize the ILogger and IMsalHttpClientFactory interfaces

public UsernamePasswordAuthenticationProvider(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

UsernamePasswordAuthenticationProvider(string, string, PnPCoreAuthenticationUsernamePasswordOptions)

Public constructor for external consumers of the library

public UsernamePasswordAuthenticationProvider(string clientId, string tenantId, PnPCoreAuthenticationUsernamePasswordOptions options)

Parameters

clientId string

The Client ID for the Authentication Provider

tenantId string

The Tenant ID for the Authentication Provider

options PnPCoreAuthenticationUsernamePasswordOptions

Options for the authentication provider

UsernamePasswordAuthenticationProvider(string, string, string, SecureString)

Public constructor for external consumers of the library

public UsernamePasswordAuthenticationProvider(string clientId, string tenantId, string username, SecureString password)

Parameters

clientId string

The Client ID for the Authentication Provider

tenantId string

The Tenant ID for the Authentication Provider

username string

The Username for authentication

password SecureString

The Password for authentication

Properties

Password

The password for authenticating

public SecureString Password { get; set; }

Property Value

SecureString

Username

The username for authenticating

public string Username { get; set; }

Property Value

string

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