亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ASP.NET標識的IUserSecurityStampStore<TUser>接口是什么?

ASP.NET標識的IUserSecurityStampStore<TUser>接口是什么?

波斯汪 2019-10-13 12:08:59
ASP.NET標識的IUserSecurityStampStore<TUser>接口是什么?查看ASP.NET標識(ASP.NET中的新成員關系實現),我在實現自己的接口時遇到了這個接口UserStore://Microsoft.AspNet.Identity.Core.dllnamespace Microsoft.AspNet.Identity{      public interface IUserSecurityStampStore<TUser> :     {         // Methods         Task<string> GetSecurityStampAsync(TUser user);         Task SetSecurityStampAsync(TUser user, string stamp);     }}IUserSecurityStampStore在默認情況下實現。EntityFramework.UserStore<TUser>從本質上獲取并設置TUser.SecurityStamp財產。經過進一步的挖掘,似乎SecurityStamp是Guid中的關鍵點新生成的UserManager(例如,更改密碼)。除了這個,我不能破譯更多的代碼,因為我正在檢查這段代碼反射器..幾乎所有的符號和異步信息都被優化了。此外,谷歌對此也沒有多大幫助。問題如下:什么是SecurityStamp在ASP.NET標識中,它用于什么?是否SecurityStamp在創建身份驗證cookie時扮演什么角色?是否需要采取任何安全措施或預防措施?例如,不要將此值向下發送給客戶端?這里有源代碼:https://github.com/aspnet/Identity/https://github.com/aspnet/Security/
查看完整描述

3 回答

?
MM們

TA貢獻1886條經驗 獲得超2個贊

這意味著表示用戶憑據的當前快照。因此,如果沒有變化,郵票將保持不變。但是,如果用戶的密碼被更改,或者登錄被刪除(取消鏈接您的Google/FB帳戶),郵票就會改變。當出現這種情況時,需要自動對用戶簽名/拒絕舊cookie,這是2.0版的一個特性。

標識還不是開源的,它目前仍在醞釀中。

更新為2.0.0。所以主要的目的是SecurityStamp就是讓所有地方都能簽字。其基本思想是,每當用戶更改與安全有關的內容(如密碼)時,自動使cookie中的任何現有標識失效是一個好主意,因此,如果您的密碼/帳戶先前被破壞,攻擊者將不再具有訪問權限。

在2.0.0中,我們添加了以下配置來掛起OnValidateIdentity方法中的CookieMiddleware看看SecurityStamp當曲奇變的時候拒絕它。它還會自動刷新數據庫中的用戶聲明refreshInterval如果郵票沒有改變(這會處理一些事情,比如角色的改變等等)

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))
    }});

如果應用程序想要顯式地觸發這種行為,它可以調用:

UserManager.UpdateSecurityStampAsync(userId);



查看完整回答
反對 回復 2019-10-14
?
狐的傳說

TA貢獻1804條經驗 獲得超3個贊

我觀察到了令牌驗證所需的安全印章。

要回購:將數據庫中的SecurityStamp設置為null,生成一個令牌(Works,ok),驗證令牌(失敗)



查看完整回答
反對 回復 2019-10-14
?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

UseCookieAuthentication是棄用到現在為止。我設法使用

services.Configure<SecurityStampValidatorOptions>(o => 
    o.ValidationInterval = TimeSpan.FromSeconds(10));

從回復移到回答請求.


查看完整回答
反對 回復 2019-10-14
  • 3 回答
  • 0 關注
  • 543 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號