Is there a way to port this WS-Trust code to .NET Core?

2.5k Views Asked by At

I have some legacy code (.NET framework) that I want to port to .NET Core 2.1. The intent is to retrieve a token from a WS-Trust compatible STS in order to make calls to WCF services.

The code will effectively run in a new web services layer that needs to fit in the middle of existing systems. These systems may not be able to be modified extensively hence why I am attempting to carry over as much of what already exists as possible.

This will run in an AWS Lambda function hence the .NET Core constraint.

I have looked online but can't find anything that clearly explains how it could be done.

Here's the code to be ported:

var factory = new WSTrustChannelFactory("stsEndpoint") { TrustVersion = TrustVersion.WSTrust13 };
var channel = factory.CreateChannel();
var rst = new RequestSecurityToken
{
    RequestType = WSTrust13Constants.RequestTypes.Issue,
    AppliesTo = new EndpointAddress("endpoint"),
    Context = "context",
};

rst.Claims.Dialect = "http://docs.oasis-open.org/wsfed/authorization/200706/authclaims";
rst.Claims.Add(new RequestClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role", true, "principal"));
rst.Claims.Add(new RequestClaim("request", true, id));
var token = channel.Issue(rst, out RequestSecurityTokenResponse rstr);
0

There are 0 best solutions below