繁体   English   中英

在使用C#的ASP.NET网页中,OAuthWebSecurity的“ RequestAuthentication()”和“ VerifyAuthentication()”方法有何区别?

[英]What's the Difference Between OAuthWebSecurity's “RequestAuthentication()” and “VerifyAuthentication()” methods in ASP.NET-Webpages with C#?

我正在尝试真正“弄清楚”使用OAuth时发生的情况(实际上仅将其用于Google),但是我似乎不太了解以下两者之间的区别:

OAuthWebSecurity.RequestAuthentication("Google", Href("~/Account/RegisterService.cshtml"));

和:

OAuthWebSecurity.VerifyAuthentication(Href("~/Account/RegisterService.cshtml"));

在“ http://msdn.microsoft.com ”上,他们将区别描述为:

RequestAuthentication():

通过将用户定向到外部网站来请求指定的提供程序启动身份验证,并在身份验证成功时指示提供程序将用户重定向到指定的URL。

(位于此处: http : //msdn.microsoft.com/zh-cn/library/microsoft.web.webpages.oauth.oauthwebsecurity.requestauthentication (v= vs.111 ) .aspx

VerifyAuthentication():

返回一个值,该值指示提供者是否已确认用户帐户。

(位于此处: http : //msdn.microsoft.com/zh-cn/library/microsoft.web.webpages.oauth.oauthwebsecurity.verifyauthentication (v= vs.111 ) .aspx

因此,我想问题归结为它们的“已认证”和“已确认”含义之间的区别是什么。

RequestAuthentication将把用户重定向到网站并要求登录。 输入凭据并为您的应用程序授予权限后,它将返回您的网站(returnUrl)。

回来后,您应该使用VerifyAuthentication验证提供者返回的令牌。

var result = OAuthWebSecurity.VerifyAuthentication();

if (result.IsSuccessful)
{
    var provider = result.Provider;
    var uniqueUserID = result.ProviderUserId;
}

因此,应在将用户重定向到提供程序以登录/授予访问权限时调用RequestAuthentication (用户登录并同意)

VerifyAuthentication是下面的验证部分。

IMG

暂无
暂无

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

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