【问题标题】:Connecting to Service Fabric using anapplication使用应用程序连接到 Service Fabric
【发布时间】:2019-03-22 08:29:34
【问题描述】:

我想使用应用程序远程连接到 Service Fabric。目前,我们使用用户名/密码进行连接,这不是很安全。如果我运行下面的代码,它会返回给定的应用程序不是 Service Fabric 群集的管理员。我似乎无法以管理员身份添加应用程序,只有用户。有没有人这样做过?网上关于它的很少。

string token = GetAccessToken(tenantID, clusterApplicationId, clusterSecret);

                var claimsCredentials = new ClaimsCredentials();
                claimsCredentials.ServerThumbprints.Add(serverCertThumb);
                claimsCredentials.LocalClaims = token;

                try
                {
                    var fc = new FabricClient(claimsCredentials, connection);
                    var ret = fc.ClusterManager.GetClusterManifestAsync().Result;
                    Console.WriteLine(ret.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Connect failed: {0}", e.Message);
                }


        private static string GetAccessToken(string tenantId, string clientId, string secretKey)
        {
            string resource = "https://graph.microsoft.com";
            string authorityFormat = @"https://login.microsoftonline.com/{0}";
            string authority = string.Format(CultureInfo.InvariantCulture, authorityFormat, tenantId);
            var authContext = new AuthenticationContext(authority);
            var clientCredential = new ClientCredential(clientId, secretKey);
            var authResult = authContext.AcquireTokenAsync(resource, clientCredential).Result;
            return authResult.AccessToken;
        }

【问题讨论】:

  • 您能否添加运行代码时遇到的确切错误?
  • 问题解决了吗?当我尝试fc.ClusterManager.GetClusterManifestAsync().Result; 时,该调用会起作用并返回清单。我用简单的new FabricClient();初始化了客户端。

标签: c# web-applications active-directory azure-active-directory azure-service-fabric


【解决方案1】:

如果您使用应用程序通过 client credential flow 获取 access_token,它会在调用另一个 Web 服务时使用自己的凭据而不是模拟用户来进行身份验证。在 azure 门户中,您可以将角色分配给应用程序,或者只是通过委派权限来模拟用户。

【讨论】:

    猜你喜欢
    • 2018-03-03
    • 2015-12-24
    • 1970-01-01
    • 2019-02-21
    • 2016-09-11
    • 2020-01-29
    • 2016-11-23
    • 2016-07-26
    • 2016-09-29
    相关资源
    最近更新 更多