簡體   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