4

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);
Norman
  • 439
  • 3
  • 9
  • 1
    Have you tried just trying it out? Switch out the Target Framework from .NET X to .Net Core 2.1 (why not 3.0? or even 2.2?) . You can use [this](https://learn.microsoft.com/en-us/dotnet/core/porting/) microsoft docs entry to help with porting – MindSwipe Oct 18 '19 at 07:34
  • I have, but there are parts of the above code which appear to be incompatible, although System.ServiceModel.Security gets me most of the way there. The article on porting .NET framework code looks helpful, thanks. I'll take more of a look at it on Monday. – Norman Oct 18 '19 at 10:54
  • 1
    Maybe also try .NET Core 3.0 as it has achieved something like 98% (citation needed) feature completeness and released as stable a few weeks ago – MindSwipe Oct 18 '19 at 10:58
  • Thanks for the suggestion. It's at about 80% of the total surface area of the .NET framework monolith (https://github.com/dotnet/announcements/issues/130). It is possible to move to .NET Core 3.0 on Lambda through a custom runtime. I gave it a go and it still has issues with some of the legacy assemblies (specifically System.ServiceModel). I'm more wondering if anyone has approached the problem described natively in .NET Core. Or even if there's a way through jumping through hoops to do it less natively. – Norman Oct 19 '19 at 06:18
  • 1
    Looks like support is planned but not yet generally available: https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/852#issuecomment-540825912 – Norman Oct 20 '19 at 23:40

0 Answers0