如何管理ACS服务标识

时间:2013-04-17 15:11:29

标签: c# azure azure-web-roles acs acs-serviceidentity

我在azure WebRole中托管WCF 4.5服务 我使用Azure ACS服务标识来管理我的wcf用户(主动身份验证)。 我接受这个模型是因为我们的用户数量有限

现在我想知道如何通过C#代码管理(创建/读取/更新/删除)ACS服务标识以编程方式

2 个答案:

答案 0 :(得分:5)

查看具有ACS Management Service API管理权的ServiceIdentity

管理端点位于此处:
https://NAMESPACE.accesscontrol.windows.net/v2/mgmt/service

您可以利用此ACS管理服务创建新的ServiceIdentities

string name = "SampleServiceIdentity";
string password = "SampleServiceIdentityPassword";
ServiceIdentity sid = new ServiceIdentity()
{
    Name = name
};

DateTime startDate, endDate;
startDate = DateTime.UtcNow;
endDate = DateTime.MaxValue;

ServiceIdentityKey key = new ServiceIdentityKey()
{
    EndDate = endDate.ToUniversalTime(),
    StartDate = startDate.ToUniversalTime(),
    Type = "Password",
    Usage = "Password",
    Value = Encoding.UTF8.GetBytes(password),
    DisplayName = String.Format(CultureInfo.InvariantCulture, "{0} key for {1}", "Password", name)
};

svc.AddToServiceIdentities(sid);
svc.AddRelatedObject(
    sid,
    "ServiceIdentityKeys",
    key);


svc.SaveChanges(SaveChangesOptions.Batch);

此示例来自MSDN - How to: Use ACS Management Service to Configure Service Identies

答案 1 :(得分:1)

一个简单的如何演示名为以编程方式调用ACS管理服务here