編輯23/08/2016 我想你是在cookie認證與身份
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
// Configure the sign in cookie
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
這是Visual Studio中具有標識的默認配置。 我可以爭論爲什麼它不是安全的好選擇,但那不是重點。
你可以去白衣它的「郵遞員」,但它的棘手 這是我要做的事:
- 請在您的登錄頁面的請求:
- 獲取的反僞造令牌形式:
- 請登錄頁面上POST請求與以數據的形式這個post數據:
現在你的郵遞員得到驗證cookie,你可以請求Web API與[授權]標籤
編輯
對於工具,你必須添加一個授權頭。
- 圍棋的頭形式
- 添加的HTTP標頭 「授權」
- 單擊編輯按鈕等瞧;)
screen shot
以前的答案被刪除
這是用於基本身份驗證,取決於您的身份驗證機制 – Mathieu
我正在使用身份。我用上面的方法,但仍然得到認證錯誤,像這樣http://prntscr.com/c908zb –
我添加一個方法去cookie認證。每次認證會話關閉時,您都必須這樣做。我建議你切換到基於令牌的身份驗證,如果你必須從例如電話應用程序使用你的網絡API,例如。維護電話應用程序的cookie是一團糟;) – Mathieu