Sending WIF ID to RAP Service in WebAPI

I read this article: Delegating Identities Using AD FS 2.0 Walkthrough  on how to perform delegation authentication using WIF from an ASP.NET application to the WCF service on the back panel. I currently have an ASP.NET WebAPI REST service that I want to get from my ASP.NET application using delegation of authority, but I cannot find any information on how to do this. This technical article is used CreateChannelActingAsto create a channel for a WCF service using the caller’s security token, but obviously this method is not applicable to the REST API. Can someone point me to some articles or give a description of how I can delegate authentication using WIF for my REST service?

The WebAPI REST service application is already configured and works using WIF authentication using this library from Thinktecture.

+1
source share
1 answer

( Thinktecture Identity Server). , - (webappaccount) , , Identity Delegation- > Add Realm , - 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 .

0

Source: https://habr.com/ru/post/1544270/


All Articles