C# Class OfficeDevPnP.Core.AuthenticationManager

This manager class can be used to obtain a SharePointContext object
Show file Open project: OfficeDev/PnP-Sites-Core Class Usage Examples

Public Methods

Method Description
GetADFSCertificateMixedAuthenticationContext ( string siteUrl, string serialNumber, string sts, string idpId, int logonTokenCacheExpirationWindow = 10 ) : ClientContext
GetADFSUserNameMixedAuthenticatedContext ( string siteUrl, string user, string password, string domain, string sts, string idpId, int logonTokenCacheExpirationWindow = 10 ) : ClientContext

Returns a SharePoint on-premises ClientContext for sites secured via ADFS

GetAppOnlyAuthenticatedContext ( string siteUrl, string appId, string appSecret ) : ClientContext

Returns an app only ClientContext object

GetAppOnlyAuthenticatedContext ( string siteUrl, string realm, string appId, string appSecret, string acsHostUrl = "accesscontrol.windows.net", string globalEndPointPrefix = "accounts" ) : ClientContext

Returns an app only ClientContext object

GetAzureADAccessTokenAuthenticatedContext ( String siteUrl, String accessToken ) : ClientContext

Returns a SharePoint ClientContext using Azure Active Directory authentication. This requires that you have a Azure AD Web Application registered. The user will not be prompted for authentication, the current user's authentication context will be used by leveraging an explicit OAuth 2.0 Access Token value.

GetAzureADAppOnlyAuthenticatedContext ( string siteUrl, string clientId, string tenant, StoreName storeName, StoreLocation storeLocation, string thumbPrint, AzureEnvironment environment = AzureEnvironment.Production ) : ClientContext

Returns a SharePoint ClientContext using Azure Active Directory App Only Authentication. This requires that you have a certificated created, and updated the key credentials key in the application manifest in the azure AD accordingly.

GetAzureADAppOnlyAuthenticatedContext ( string siteUrl, string clientId, string tenant, X509Certificate2 certificate, AzureEnvironment environment = AzureEnvironment.Production ) : ClientContext

Returns a SharePoint ClientContext using Azure Active Directory App Only Authentication. This requires that you have a certificated created, and updated the key credentials key in the application manifest in the azure AD accordingly.

GetAzureADAppOnlyAuthenticatedContext ( string siteUrl, string clientId, string tenant, string certificatePath, SecureString certificatePassword, AzureEnvironment environment = AzureEnvironment.Production ) : ClientContext

Returns a SharePoint ClientContext using Azure Active Directory App Only Authentication. This requires that you have a certificated created, and updated the key credentials key in the application manifest in the azure AD accordingly.

GetAzureADAppOnlyAuthenticatedContext ( string siteUrl, string clientId, string tenant, string certificatePath, string certificatePassword, AzureEnvironment environment = AzureEnvironment.Production ) : ClientContext

Returns a SharePoint ClientContext using Azure Active Directory App Only Authentication. This requires that you have a certificated created, and updated the key credentials key in the application manifest in the azure AD accordingly.

GetAzureADNativeApplicationAuthenticatedContext ( string siteUrl, string clientId, Uri redirectUri, TokenCache tokenCache = null ) : ClientContext

Returns a SharePoint ClientContext using Azure Active Directory authentication. This requires that you have a Azure AD Native Application registered. The user will be prompted for authentication.

GetAzureADNativeApplicationAuthenticatedContext ( string siteUrl, string clientId, string redirectUrl, TokenCache tokenCache = null ) : ClientContext

Returns a SharePoint ClientContext using Azure Active Directory authentication. This requires that you have a Azure AD Native Application registered. The user will be prompted for authentication.

GetAzureADWebApplicationAuthenticatedContext ( String siteUrl, String>.Func accessTokenGetter ) : ClientContext

Returns a SharePoint ClientContext using Azure Active Directory authentication. This requires that you have a Azure AD Web Application registered. The user will not be prompted for authentication, the current user's authentication context will be used by leveraging ADAL.

GetNetworkCredentialAuthenticatedContext ( string siteUrl, string user, SecureString password, string domain ) : ClientContext

Returns a SharePoint on-premises / SharePoint Online Dedicated ClientContext object

GetNetworkCredentialAuthenticatedContext ( string siteUrl, string user, string password, string domain ) : ClientContext

Returns a SharePoint on-premises / SharePoint Online Dedicated ClientContext object

GetSharePointOnlineAuthenticatedContextTenant ( string siteUrl, string tenantUser, SecureString tenantUserPassword ) : ClientContext

Returns a SharePointOnline ClientContext object

GetSharePointOnlineAuthenticatedContextTenant ( string siteUrl, string tenantUser, string tenantUserPassword ) : ClientContext

Returns a SharePointOnline ClientContext object

GetWebLoginClientContext ( string siteUrl, System icon = null ) : ClientContext

Returns a SharePoint on-premises / SharePoint Online ClientContext object. Requires claims based authentication with FedAuth cookie.

RefreshADFSCertificateMixedAuthenticationContext ( string siteUrl, string serialNumber, string sts, string idpId, int logonTokenCacheExpirationWindow = 10 ) : void
RefreshADFSUserNameMixedAuthenticatedContext ( string siteUrl, string user, string password, string domain, string sts, string idpId, int logonTokenCacheExpirationWindow = 10 ) : void

Refreshes the SharePoint FedAuth cookie

Private Methods

Method Description
AcquireNativeApplicationTokenAsync ( string authContextUrl, string resourceId ) : Task
EnsureToken ( string siteUrl, string realm, string appId, string appSecret, string acsHostUrl, string globalEndPointPrefix ) : void
GetAccessTokenLease ( System.DateTime expiresOn ) : System.TimeSpan

Get the access token lease time span.

clientContext_NativeApplicationExecutingWebRequest ( object sender, WebRequestEventArgs e ) : void

Method Details

GetADFSCertificateMixedAuthenticationContext() public method

public GetADFSCertificateMixedAuthenticationContext ( string siteUrl, string serialNumber, string sts, string idpId, int logonTokenCacheExpirationWindow = 10 ) : ClientContext
siteUrl string
serialNumber string
sts string
idpId string
logonTokenCacheExpirationWindow int
return ClientContext

GetADFSUserNameMixedAuthenticatedContext() public method

Returns a SharePoint on-premises ClientContext for sites secured via ADFS
public GetADFSUserNameMixedAuthenticatedContext ( string siteUrl, string user, string password, string domain, string sts, string idpId, int logonTokenCacheExpirationWindow = 10 ) : ClientContext
siteUrl string Url of the SharePoint site that's secured via ADFS
user string Name of the user (e.g. administrator)
password string Password of the user
domain string Windows domain of the user
sts string Hostname of the ADFS server (e.g. sts.company.com)
idpId string Identifier of the ADFS relying party that we're hitting
logonTokenCacheExpirationWindow int Optioanlly provide the value of the SharePoint STS logonTokenCacheExpirationWindow. Defaults to 10 minutes.
return ClientContext

GetAppOnlyAuthenticatedContext() public method

Returns an app only ClientContext object
public GetAppOnlyAuthenticatedContext ( string siteUrl, string appId, string appSecret ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
appId string Application ID which is requesting the ClientContext object
appSecret string Application secret of the Application which is requesting the ClientContext object
return ClientContext

GetAppOnlyAuthenticatedContext() public method

Returns an app only ClientContext object
public GetAppOnlyAuthenticatedContext ( string siteUrl, string realm, string appId, string appSecret, string acsHostUrl = "accesscontrol.windows.net", string globalEndPointPrefix = "accounts" ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
realm string Realm of the environment (tenant) that requests the ClientContext object
appId string Application ID which is requesting the ClientContext object
appSecret string Application secret of the Application which is requesting the ClientContext object
acsHostUrl string Azure ACS host, defaults to accesscontrol.windows.net but internal pre-production environments use other hosts
globalEndPointPrefix string Azure ACS endpoint prefix, defaults to accounts but internal pre-production environments use other prefixes
return ClientContext

GetAzureADAccessTokenAuthenticatedContext() public method

Returns a SharePoint ClientContext using Azure Active Directory authentication. This requires that you have a Azure AD Web Application registered. The user will not be prompted for authentication, the current user's authentication context will be used by leveraging an explicit OAuth 2.0 Access Token value.
public GetAzureADAccessTokenAuthenticatedContext ( String siteUrl, String accessToken ) : ClientContext
siteUrl String Site for which the ClientContext object will be instantiated
accessToken String An explicit value for the AccessToken
return ClientContext

GetAzureADAppOnlyAuthenticatedContext() public method

Returns a SharePoint ClientContext using Azure Active Directory App Only Authentication. This requires that you have a certificated created, and updated the key credentials key in the application manifest in the azure AD accordingly.
public GetAzureADAppOnlyAuthenticatedContext ( string siteUrl, string clientId, string tenant, StoreName storeName, StoreLocation storeLocation, string thumbPrint, AzureEnvironment environment = AzureEnvironment.Production ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
clientId string The Azure AD Application Client ID
tenant string The Azure AD Tenant, e.g. mycompany.onmicrosoft.com
storeName StoreName The name of the store for the certificate
storeLocation StoreLocation The location of the store for the certificate
thumbPrint string The thumbprint of the certificate to locate in the store
environment AzureEnvironment Indicates which Azure AD environment is being used
return ClientContext

GetAzureADAppOnlyAuthenticatedContext() public method

Returns a SharePoint ClientContext using Azure Active Directory App Only Authentication. This requires that you have a certificated created, and updated the key credentials key in the application manifest in the azure AD accordingly.
public GetAzureADAppOnlyAuthenticatedContext ( string siteUrl, string clientId, string tenant, X509Certificate2 certificate, AzureEnvironment environment = AzureEnvironment.Production ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
clientId string The Azure AD Application Client ID
tenant string The Azure AD Tenant, e.g. mycompany.onmicrosoft.com
certificate System.Security.Cryptography.X509Certificates.X509Certificate2
environment AzureEnvironment
return ClientContext

GetAzureADAppOnlyAuthenticatedContext() public method

Returns a SharePoint ClientContext using Azure Active Directory App Only Authentication. This requires that you have a certificated created, and updated the key credentials key in the application manifest in the azure AD accordingly.
public GetAzureADAppOnlyAuthenticatedContext ( string siteUrl, string clientId, string tenant, string certificatePath, SecureString certificatePassword, AzureEnvironment environment = AzureEnvironment.Production ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
clientId string The Azure AD Application Client ID
tenant string The Azure AD Tenant, e.g. mycompany.onmicrosoft.com
certificatePath string The path to the certificate (*.pfx) file on the file system
certificatePassword System.Security.SecureString Password to the certificate
environment AzureEnvironment Indicates which Azure AD environment is being used
return ClientContext

GetAzureADAppOnlyAuthenticatedContext() public method

Returns a SharePoint ClientContext using Azure Active Directory App Only Authentication. This requires that you have a certificated created, and updated the key credentials key in the application manifest in the azure AD accordingly.
public GetAzureADAppOnlyAuthenticatedContext ( string siteUrl, string clientId, string tenant, string certificatePath, string certificatePassword, AzureEnvironment environment = AzureEnvironment.Production ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
clientId string The Azure AD Application Client ID
tenant string The Azure AD Tenant, e.g. mycompany.onmicrosoft.com
certificatePath string The path to the certificate (*.pfx) file on the file system
certificatePassword string Password to the certificate
environment AzureEnvironment Indicates which Azure AD environment is being used
return ClientContext

GetAzureADNativeApplicationAuthenticatedContext() public method

Returns a SharePoint ClientContext using Azure Active Directory authentication. This requires that you have a Azure AD Native Application registered. The user will be prompted for authentication.
public GetAzureADNativeApplicationAuthenticatedContext ( string siteUrl, string clientId, Uri redirectUri, TokenCache tokenCache = null ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
clientId string The Azure AD Native Application Client ID
redirectUri System.Uri The Azure AD Native Application Redirect Uri
tokenCache Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache Optional token cache. If not specified an in-memory token cache will be used
return ClientContext

GetAzureADNativeApplicationAuthenticatedContext() public method

Returns a SharePoint ClientContext using Azure Active Directory authentication. This requires that you have a Azure AD Native Application registered. The user will be prompted for authentication.
public GetAzureADNativeApplicationAuthenticatedContext ( string siteUrl, string clientId, string redirectUrl, TokenCache tokenCache = null ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
clientId string The Azure AD Native Application Client ID
redirectUrl string The Azure AD Native Application Redirect Uri as a string
tokenCache Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache Optional token cache. If not specified an in-memory token cache will be used
return ClientContext

GetAzureADWebApplicationAuthenticatedContext() public method

Returns a SharePoint ClientContext using Azure Active Directory authentication. This requires that you have a Azure AD Web Application registered. The user will not be prompted for authentication, the current user's authentication context will be used by leveraging ADAL.
public GetAzureADWebApplicationAuthenticatedContext ( String siteUrl, String>.Func accessTokenGetter ) : ClientContext
siteUrl String Site for which the ClientContext object will be instantiated
accessTokenGetter String>.Func The AccessToken getter method to use
return ClientContext

GetNetworkCredentialAuthenticatedContext() public method

Returns a SharePoint on-premises / SharePoint Online Dedicated ClientContext object
public GetNetworkCredentialAuthenticatedContext ( string siteUrl, string user, SecureString password, string domain ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
user string User to be used to instantiate the ClientContext object
password System.Security.SecureString Password (SecureString) of the user used to instantiate the ClientContext object
domain string Domain of the user used to instantiate the ClientContext object
return ClientContext

GetNetworkCredentialAuthenticatedContext() public method

Returns a SharePoint on-premises / SharePoint Online Dedicated ClientContext object
public GetNetworkCredentialAuthenticatedContext ( string siteUrl, string user, string password, string domain ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
user string User to be used to instantiate the ClientContext object
password string Password of the user used to instantiate the ClientContext object
domain string Domain of the user used to instantiate the ClientContext object
return ClientContext

GetSharePointOnlineAuthenticatedContextTenant() public method

Returns a SharePointOnline ClientContext object
public GetSharePointOnlineAuthenticatedContextTenant ( string siteUrl, string tenantUser, SecureString tenantUserPassword ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
tenantUser string User to be used to instantiate the ClientContext object
tenantUserPassword System.Security.SecureString Password (SecureString) of the user used to instantiate the ClientContext object
return ClientContext

GetSharePointOnlineAuthenticatedContextTenant() public method

Returns a SharePointOnline ClientContext object
public GetSharePointOnlineAuthenticatedContextTenant ( string siteUrl, string tenantUser, string tenantUserPassword ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
tenantUser string User to be used to instantiate the ClientContext object
tenantUserPassword string Password of the user used to instantiate the ClientContext object
return ClientContext

GetWebLoginClientContext() public method

Returns a SharePoint on-premises / SharePoint Online ClientContext object. Requires claims based authentication with FedAuth cookie.
public GetWebLoginClientContext ( string siteUrl, System icon = null ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
icon System Optional icon to use for the popup form
return ClientContext

RefreshADFSCertificateMixedAuthenticationContext() public method

public RefreshADFSCertificateMixedAuthenticationContext ( string siteUrl, string serialNumber, string sts, string idpId, int logonTokenCacheExpirationWindow = 10 ) : void
siteUrl string
serialNumber string
sts string
idpId string
logonTokenCacheExpirationWindow int
return void

RefreshADFSUserNameMixedAuthenticatedContext() public method

Refreshes the SharePoint FedAuth cookie
public RefreshADFSUserNameMixedAuthenticatedContext ( string siteUrl, string user, string password, string domain, string sts, string idpId, int logonTokenCacheExpirationWindow = 10 ) : void
siteUrl string Url of the SharePoint site that's secured via ADFS
user string Name of the user (e.g. administrator)
password string Password of the user
domain string Windows domain of the user
sts string Hostname of the ADFS server (e.g. sts.company.com)
idpId string Identifier of the ADFS relying party that we're hitting
logonTokenCacheExpirationWindow int Optioanlly provide the value of the SharePoint STS logonTokenCacheExpirationWindow. Defaults to 10 minutes.
return void