繁体   English   中英

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

[英]Owin auth - how to get IP address of client requesting the auth token

使用Owin Security,我试图让API有2种身份验证方法。

context变量( OAuthGrantResourceOwnerCredentialsContext )中是否有属性允许我访问向API发送auth令牌的初始请求的客户端IP地址

我的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 )?

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

var remoteIpAddresss = context.Request.RemoteIpAddress;

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

var localIpAddress = context.Request.LocalIpAddress;

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM