【问题标题】:WIF return to the RP applicationWIF返回RP申请
【发布时间】:2011-09-03 23:19:21
【问题描述】:

我正在构建 WIF STS,并且能够生成令牌。如何将令牌返回到原始 URL。我注意到这存在于 wctx 参数中,格式为 ru=。如何在不手动将其解析为字符串的情况下提取它?

【问题讨论】:

    标签: c# wif


    【解决方案1】:

    如果你想将令牌返回给依赖方,你可以使用类似这样的ProcessRequest方法:

        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 参数,请查看 WSFederationMessage.CreateFromUri

    【讨论】:

    • 感谢您的回复。我已经在做几乎相同的事情了。但是我们需要重写 GetScope 方法并分配一个 ReplyTo 参数。这是我有点困惑的地方。如何从上下文变量中提取值?因为我想用新创建的令牌命中 RP 端点。
    • 您可以在您的SecurityTokenService 派生类中覆盖GetScope。如果您想更改回复,只需使用以下内容:protected override Scope GetScope( Microsoft.IdentityModel.Claims.IClaimsPrincipal principal, RequestSecurityToken request) { Scope scope = new Scope(request); scope.ReplyToAddress = yourAddress; return scope; }
    • 感谢能够解决这个问题。我试图手动将AppliesTo URL解析为Reply参数,而不是在配置中设置它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 1970-01-01
    相关资源
    最近更新 更多