/// <summary> /// Initializes the configuration options for the target Authentication Provider /// </summary> /// <param name="provider">The target Authentication Provider</param> /// <param name="option">The configuration options for the target Authentication Provider</param> private static void InitProviderOptions(IAuthenticationProvider provider, PnPCoreAuthenticationCredentialConfigurationOptions option) { switch (provider) { case X509CertificateAuthenticationProvider x509Certificate: x509Certificate.ClientId = option.ClientId; x509Certificate.TenantId = option.TenantId; x509Certificate.Certificate = X509CertificateUtility.LoadCertificate( option.X509Certificate.StoreName, option.X509Certificate.StoreLocation, option.X509Certificate.Thumbprint); break; case ExternalAuthenticationProvider aspNetCore: aspNetCore.ClientId = option.ClientId; aspNetCore.TenantId = option.TenantId; break; case CredentialManagerAuthenticationProvider credentialManager: credentialManager.ClientId = option.ClientId; credentialManager.TenantId = option.TenantId; credentialManager.CredentialManagerName = option.CredentialManager.CredentialManagerName; break; case OnBehalfOfAuthenticationProvider onBehalfOf: onBehalfOf.ClientId = option.ClientId; onBehalfOf.TenantId = option.TenantId; onBehalfOf.ClientSecret = option.OnBehalfOf.ClientSecret.ToSecureString(); break; case UsernamePasswordAuthenticationProvider usernamePassword: usernamePassword.ClientId = option.ClientId; usernamePassword.TenantId = option.TenantId; usernamePassword.Username = option.UsernamePassword.Username; usernamePassword.Password = option.UsernamePassword.Password.ToSecureString(); break; case InteractiveAuthenticationProvider interactive: interactive.ClientId = option.ClientId; interactive.TenantId = option.TenantId; interactive.RedirectUri = option.Interactive.RedirectUri; break; case DeviceCodeAuthenticationProvider deviceCode: deviceCode.ClientId = option.ClientId; deviceCode.TenantId = option.TenantId; deviceCode.RedirectUri = option.Interactive.RedirectUri; break; } }
public void X509CertUtilityEncryptNothingTest() { var certificate = X509CertificateUtility.LoadCertificate(StoreName.My, StoreLocation.CurrentUser, TestCommon.GetX509CertificateThumbprint()); Assert.ThrowsException <ArgumentNullException>(() => X509CertificateUtility.Encrypt(null, certificate)); }
/// <summary> /// 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. /// </summary> /// <param name="siteUrl">Site for which the ClientContext object will be instantiated</param> /// <param name="clientId">The Azure AD Application Client ID</param> /// <param name="tenant">The Azure AD Tenant, e.g. mycompany.onmicrosoft.com</param> /// <param name="storeName">The name of the store for the certificate</param> /// <param name="storeLocation">The location of the store for the certificate</param> /// <param name="thumbPrint">The thumbprint of the certificate to locate in the store</param> /// <returns></returns> public ClientContext GetAzureADAppOnlyAuthenticatedContext(string siteUrl, string clientId, string tenant, StoreName storeName, StoreLocation storeLocation, string thumbPrint) { var cert = X509CertificateUtility.LoadCertificate(storeName, storeLocation, thumbPrint); return(GetAzureADAppOnlyAuthenticatedContext(siteUrl, clientId, tenant, cert)); }