Owin auth - 如何获取请求身份验证令牌的客户端的IP地址

时间:2015-03-05 07:15:34

标签: c# .net authentication owin

使用Owin Security,我正在尝试使API有两种身份验证方法。

context变量(OAuthGrantResourceOwnerCredentialsContext)中是否有属性允许我访问发送初始请求的客户端 IP地址对于API的身份验证令牌?

我的auth方法的基本条带如下所示:

public override async Task GrantResourceOwnerCredentials(
    OAuthGrantResourceOwnerCredentialsContext context)
{
    await Task.Run(() =>
    {
        var remoteIpAddresss = context.Request.RemoteIpAddress;
        var localIpAddress = context.Request.LocalIpAddress;


        // ... authenticate process goes here (AddClaim, etc.)
    }
}

根据我的理解,remoteIpAddresslocalIpAddress是API(即托管API的位置)。我如何知道请求从哪个IP地址(和端口)发送?

客户是否需要自己发送此信息?

我应该在auth路径中添加额外的参数吗? (除了典型的usernamepasswordgrant_type)?

1 个答案:

答案 0 :(得分:19)

所以,回答我自己的问题,如果我错了,请纠正我,但是:

var remoteIpAddresss = context.Request.RemoteIpAddress;

客户端的IP 地址(请求身份验证令牌的用户),

var localIpAddress = context.Request.LocalIpAddress;

Web Api的IP 地址(托管API的地方)。

相关问题