2017-11-15 18 views
1

私はIdentityServer4の新機能です。私はIPersistedGrantStoreを実装して、リフレッシュトークンをデータベースにPersistedGrantsのようなテーブルに保存する必要があることを知りました。IdentityServer4 - mysql.dataを使用してリフレッシュトークンをデータベースに保存する方法は?

ネイティブアプリが新しいアクセストークンを要求したときのIdentityServerログは、"refresh_token" grant with value: "{value}" not found in storeです。

私は永続化された許可ストアのメモリ内バージョンを使用しているからです。そこで、リフレッシュトークンをPersistedGrantテーブルに保存する必要があります。

したがって 私startup.csで、私は次の行を追加:

builder.Services.AddScoped<IPersistedGrantStore, PersistedGrantStore>(); 

IPersistedGrantStore.csは、だから私はCustomPersistedGrant.csクラスを持っている

public interface IPersistedGrantStore 
{   
    Task StoreAsync(CustomPersistedGrant grant); 

    Task<CustomPersistedGrant> GetAsync(string key); 

    Task<IEnumerable<CustomPersistedGrant>> GetAllAsync(string subjectId);   
} 

です

public class CustomPersistedGrant 
{ 
    public string Key { get; set; } 

    public string Type { get; set; } 

    public string SubjectId { get; set; } 

    public string ClientId { get; set; } 

    public DateTime CreationTime { get; set; } 

    public DateTime? Expiration { get; set; } 

    public string Data { get; set; } 
} 

今私は自分のPersistedGrantStore.csクラスのコードを書く必要があります。 しかし、質問は:PersistedGrantStore.csクラスのコードを書いたら、私はPersistedGrantStore.csクラスを呼び出しますか? Identity.ServerでAccount/AccountController?私はEntity Frameworkを使用したくないので、EntityFrameworkを使用しないとその例は見つかりませんでした。

ありがとうございました。

答えて

1

重要なことは、好きなバックエンドを使ってIPersistedGrantStoreを実装し、その実装を依存関係注入システムに登録することによってその実装を使用するようにIdentityServerに指示することです。

あなたが実装PersistedGrantStoreを呼び出す場合たとえば、あなたは、このような実装を登録することができが:

services.AddTransient<IPersistedGrantStore, PersistedGrantStore>();

あなたはすべてのEntityFrameworkを奪うたら、基本的に、これは、すべてのことthe EntityFramework implementation doesであることがわかりますもの。

後でIdentityServerがグラントを永続化したい場合は、実装が取得され、適切なメソッドが呼び出されます。だから、にはを実行する必要はありません。IdentityServerにインプリメンテーションを注入する以外に、必要な処理を実行できます。

+1

ありがとうございました。私の** startup.cs **では、この行で実装を登録しました: 'builder.Services.AddScoped ();'。私の目標は助成金を維持することですが、IdentityServer4で 'IPersistedGrantStore'と私の' PersistedGrantStore'を使って助成金を維持するコードはどこにありますか? QuickStartIdentityServerプロジェクトでgithub –

+0

の参照が見つかりません。これはIdentityServerの内部呼び出しです。 InMemoryバージョンを使用しているときに電話をかける必要はないので、PersistedGrantストアに電話する必要はありません。 –

+0

私の 'PersistedGrantStore'ではすべてのインターフェースメンバーを実装しました。このクラスのすべてのメソッドの始めにブレークポイントを配置してデバッグしました。問題は、アプリケーションが壊れないということですが、私が間違っているところを理解できません。クライアントを 'GrantTypes 'で設定します。Code'、 'RequireConsent = false'、' AllowOfflineAccess = true'を指定します。何か不足していますか? –

関連する問題