IdentityServer3-如果客户端在Intranet上,请重定向到ADF



我们有一个门户(MVC RDP(,内部用户(员工(和外部用户(客户(使用。我们希望IdentityServer3自动检测是否从公司网络内完成身份验证请求,并重定向到ADF。如果用户代理从Internet调用,则应显示本地登录。

简而言之,我们不想为外部IDP提供按钮,因为如果客户端在内部网络上,我们希望IDSRV自动将其重定向到ADF,以便为我们的域绑定的用户提供真实的单个符号。

如果仅内部用户使用门户网站,那么我们将仅配置客户端以仅使用特定的身份提供商,但是外部客户也使用此门户,并且这些用户未存储在我们的AD中;(

我已经研究了prowuthenticateasync并使用dns.dns.gethostname((,但这与IdentityServer正在运行的机器而不是客户端计算机有关。

在MVC控制器中,我们将仅使用request.userhostname,但这在IdentityServer3 UserVice中不可用。

我认为您可以从OwinContext获得客户端的IP地址;这样的东西:

public class UserService : UserServiceBase
{
    OwinContext ctx;
    public UserService(OwinEnvironmentService owinEnv)
    {
        ctx = new OwinContext(owinEnv.Environment);
    }
    public override Task PreAuthenticateAsync(PreAuthenticationContext context)
    {
        // The IP Address of the remote client
        var ipAddress = ctx.Environment["server.RemoteIpAddress"].ToString();
        if (BelongsToOurNetwork(ipAddress))
            context.SignInMessage.IdP = "OurADFS";
        else
            context.SignInMessage.IdP = "idsrv"; // local login
        return Task.FromResult(0);
    }
}

最新更新