C# Owin auth-如何获取请求auth令牌的客户端的IP地址
使用Owin安全性,我试图使API具有两种身份验证方法C# Owin auth-如何获取请求auth令牌的客户端的IP地址,c#,.net,authentication,owin,C#,.net,Authentication,Owin,使用Owin安全性,我试图使API具有两种身份验证方法 上下文变量(OAuthGrantResourceOwnerCredentialsContext)中是否有一个属性允许我访问向API发送身份验证令牌初始请求的客户端的IP地址 我的auth方法的基本条带如下所示: public override async Task GrantResourceOwnerCredentials( OAuthGrantResourceOwnerCredentialsContext context) {
上下文
变量(OAuthGrantResourceOwnerCredentialsContext
)中是否有一个属性允许我访问向API发送身份验证令牌初始请求的客户端的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.)
}
}
据我所知,remoteIpAddress
和localIpAddress
是API的(即API的宿主位置)。我如何知道从哪个IP地址(和端口)发送请求
客户是否需要自己发送此信息
我应该向身份验证路径添加额外的参数吗?(除了典型的
用户名
,密码
,授权类型
)?因此,为了回答我自己的问题,如果我错了,请纠正我,但是:
var remoteIpAddresss = context.Request.RemoteIpAddress;
是客户端的IP地址(请求身份验证令牌的用户),以及
是Web Api的IP地址(Api托管的位置)。我也很想知道这一点,所以我在VM上设置了一个项目(使用不同的IP),从主机向它发送了一个请求,您确实是对的
context.Request.RemoteIpAddress
显示请求令牌的客户端的IP,context.Request.LocalIpAddress
显示API所在的IP。
var localIpAddress = context.Request.LocalIpAddress;