【发布时间】: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