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

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

如何將自定義屬性添加到 IdentityServer4 PersistedGrantStore

如何將自定義屬性添加到 IdentityServer4 PersistedGrantStore

C#
明月笑刀無情 2023-09-16 17:37:14
我們將 IPersistedGrantStore 的默認實現與 EntityFramework 和 SQL Server 結合使用。我需要存儲 IP 地址(以獲取“登錄”上的“大致”位置數據),該表似乎是執行此操作的完美位置,因為它已經存儲了客戶端 ID、日期時間和刷新令牌的到期時間。是否可以擴展它并添加額外的屬性?如果我實現自己的 IPersistedGrantStore 版本,我無法“破壞”接口定義的契約并添加額外的屬性,甚至無法使用派生類(來自 IdentityServer4.Models.PersistedGrant),因為這也不會遵守接口。有什么方法可以向此表添加屬性并更新 Grant Store 實現以在調用 StoreAsync 時添加它們?
查看完整描述

1 回答

?
慕哥9229398

TA貢獻1877條經驗 獲得超6個贊

只需實現IPersistedGrantStore下面的類似代碼,您就可以完全控制持久授權,您可以添加新列來存儲。


public class PersistStore : IPersistedGrantStore

    {

        private readonly IPersistedGrandStoreService _persistedGrandStore;


        public PersistStore(IPersistedGrandStoreService persistedGrandStore)

        {

            _persistedGrandStore = persistedGrandStore;

        }


        public Task StoreAsync(PersistedGrant grant)

        {

            return _persistedGrandStore.AddAsync(grant.ToPersistedGrantModel());

        }


        public async Task<PersistedGrant> GetAsync(string key)

        {

            var grant = await _persistedGrandStore.GetAsync(key);

            return grant.ToPersistedGrant();

        }


        public async Task<IEnumerable<PersistedGrant>> GetAllAsync(string subjectId)

        {

            var grants = await _persistedGrandStore.GetAllAsync(subjectId);

            return grants.ToPersistedGrants();

        }


        public Task RemoveAsync(string key)

        {

            return _persistedGrandStore.RemoveAsync(key);

        }


        public Task RemoveAllAsync(string subjectId, string clientId)

        {

            return _persistedGrandStore.RemoveAllAsync(subjectId, clientId);

        }


        public Task RemoveAllAsync(string subjectId, string clientId, string type)

        {

            return _persistedGrandStore.RemoveAllAsync(subjectId, clientId, type);

        }

    }


查看完整回答
反對 回復 2023-09-16
  • 1 回答
  • 0 關注
  • 106 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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