3

我有 2 个 ASP.Net 应用程序:App1 和 App2。这两个应用程序都是标准的 Web 应用程序,它们使用 WIF 和同一个 ADFS 服务器来验证用户,但 App2 还公开了一些 WebAPI 服务。

当用户转到 App1 时,App1 调用 App2 上的服务,我需要以某种方式使用用户的令牌调用 App2 服务。

如果用户自己在 App2 上调用服务,他们将通过相同的 ADFS 身份验证并且一切正常,但在 App2 上调用服务的是 App1,而不是用户。

关于如何做到这一点的任何想法?

谢谢!

4

2 回答 2

4

You can use WS-Trust (ActAs) to get a delegation token:

http://weblogs.asp.net/cibrax/archive/2010/01/04/actas-in-ws-trust-1-4.aspx

Or you can do poor man's delegation:

http://www.cloudidentity.com/blog/2013/01/09/using-the-jwt-handler-for-implementing-poor-man-s-delegation-actas/

Or you could use the Thinktecture IdentityServer Adfs Bridge:

http://brockallen.com/2013/04/14/getting-json-web-tokens-jwts-from-adfs-via-thinktecture-identityservers-adfs-integration/

于 2013-07-23T00:57:13.887 回答
2

我处于同样的情况,并且一切正常。方法如下(我正在使用 Thinktecture Identity Server):

我必须设置一个委托帐户,我的 Web 应用程序使用 ( webappaccount) 来委托我的服务所在的领域,方法是转到身份委托->在身份服务器中添加领域,并且在我的 Web 应用程序中,我必须进行服务调用我的 STS 提供引导令牌以接收新的安全令牌,然后我可以使用该令牌对我的服务进行身份验证。

在我设置的网络应用程序配置中:

<system.identityModel>
    <identityConfiguration saveBootstrapContext="true">

在我的网络应用程序中,访问我的服务的代码如下所示:

BootstrapContext context = ClaimsPrincipal.Current.Identities.First().BootstrapContext as BootstrapContext;

var factory = new WSTrustChannelFactory(
    new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), _trustUrl);
factory.TrustVersion = TrustVersion.WSTrust13;

factory.Credentials.UserName.UserName = "webappaccount";
factory.Credentials.UserName.Password = "P@ssword";

var rst = new RequestSecurityToken
{
    RequestType = RequestTypes.Issue,
    KeyType = KeyTypes.Bearer,
    AppliesTo = new EndpointReference(_realm),
    ActAs = new SecurityTokenElement(context.SecurityToken)
};

var token = factory.CreateChannel().Issue(rst) as GenericXmlSecurityToken;

var client = new HttpClient
{
    BaseAddress = _baseAddress
};

client.SetToken("SAML", token.TokenXml.OuterXml);

var response = client.GetAsync("api/values").Result;

我的 REST 服务不需要任何更改。

于 2014-07-03T19:33:17.143 回答