首页 > 解决方案 > Power BI Embedded,使用证书获取身份验证令牌时出现问题 - 出现错误“无效的提供程序类型”

问题描述

我正在使用嵌入在本地 Intranet 应用程序中的 Power BI 并获取身份验证令牌,我正在使用证书。我面临的问题是,在本地进行时效果很好。但是当发布到我们的开发服务器时,它只在一个实例上工作,而不是在其他实例上,比如本地的 QA 或 UAT 环境。

这可能是什么原因?是因为我们没有正确使用证书吗?奇怪的是,如果它失败了,为什么它只适用于一个网络服务器实例而不是其他网络服务器?

****这是我们用于获取身份验证令牌的代码片段:****

            var tenantSpecificURL = AuthorityUrl.Replace("common", Tenant);
            var authenticationContext = new AuthenticationContext(tenantSpecificURL);
            AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();
            var certificatepath = AppDomain.CurrentDomain.BaseDirectory + @"App_Data\SFA.pfx";
            var xCert = new X509Certificate2(certificatepath, "XXXXXXX", X509KeyStorageFlags.PersistKeySet);
            var credential = new ClientAssertionCertificate(ApplicationId, xCert);

            //this is where i believe it is failing
            authenticationResult = authenticationContext.AcquireTokenAsync(ResourceUrl, credential).Result;

            //End of Authentication
            string AccessToken = null; //
            var m_tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
            string Token = "";

这是我得到的错误。

ExceptionMessage":"指定的提供程序类型无效。\r\n","ExceptionType":"System.Security.Cryptography.CryptographicException","StackTrace":" atSystem.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)\r\n at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\ r\n 在 System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()\r\n 在 System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)\r\n 在 System.Security.Cryptography .X509Certificates.X509Certificate2.get_PrivateKey()\r\n 在 System.IdentityModel.Tokens.X509AsymmetricSecurityKey.get_PrivateKey()\r\n 在 System.IdentityModel.Tokens.X509AsymmetricSecurityKey.GetAsymmetricAlgorithm(字符串算法,Boolean privateKey)\r\n 在 Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Platform.SigningHelper.SignWithCertificate(字符串消息,X509Certificate2 证书)\r\n 在

Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.d__59.MoveNext()"}

标签: .netpowerbix509certificatepowerbi-embeddedcryptographicexception

解决方案


推荐阅读