C# WIF返回到RP应用程序

C# WIF返回到RP应用程序,c#,wif,C#,Wif,我正在建立一个WIF STS,我能够生成一个令牌。如何将令牌返回到原始URL。我注意到这在wctx参数中以ru=的形式出现。如何在不将其手动解析为字符串的情况下提取它 如果您想将令牌返回给依赖方,您可以使用类似以下的方法: var claims = new List<Claim> { new Claim(WSIdentityConstants.ClaimTypes.Name, User.Identity.Name), new Claim

我正在建立一个WIF STS,我能够生成一个令牌。如何将令牌返回到原始URL。我注意到这在wctx参数中以ru=的形式出现。如何在不将其手动解析为字符串的情况下提取它

如果您想将令牌返回给依赖方,您可以使用类似以下的方法:

    var claims = new List<Claim>
    {
        new Claim(WSIdentityConstants.ClaimTypes.Name, User.Identity.Name),
        new Claim(ClaimTypes.AuthenticationMethod, FormsAuthenticationHelper.GetAuthenticationMethod(User.Identity))
    };

        var identity = new ClaimsIdentity(claims, STS.TokenServiceIssueTypes.Native);
        var principal = ClaimsPrincipal.CreateFromIdentity(identity);

        FederatedPassiveSecurityTokenServiceOperations.ProcessRequest(
            Request,
            principal,
            StarterTokenServiceConfiguration.Current.CreateSecurityTokenService(),
            Response);

如果您只是想提取URL参数,请查看。

谢谢您的回复。我已经在做同样的事情了。但是我们需要重写GetScope方法并分配ReplyTo参数。这就是我有点困惑的地方。如何从上下文变量中提取值?因为我想用新创建的令牌访问RP端点。您可以在SecurityTokenService派生类中重写GetScope。如果要将ReplyTo更改为,只需使用以下内容:受保护的覆盖作用域GetScope Microsoft.IdentityModel.Claims.IClaimsPrincipal,RequestSecurityToken请求{Scope Scope=new Scoperequest;Scope.ReplyToAddress=yourAddress;return Scope;}查看此处了解更多信息:感谢您能够解决此问题。我试图手动将appliestourl解析到Reply参数中,而不是在配置中设置它。