2016-12-30 4 views
2

Ich bin neu mit IdentityServer 3 und die Beispiele und Tutorial verwenden InMemory Benutzer, Client und Scope, aber ich brauche diese von DB. Also habe ich:IdentityServer 3 - Verwenden von Client und Scope von DB

Startup.cs

public void Configuration(IAppBuilder app) 
{ 
    // Allow all origins 
    app.UseCors(CorsOptions.AllowAll); 

    var factory = new IdentityServerServiceFactory(); 

    var userService = new UserService(); 
    var clientStore = new ClientStore(); 
    var scopeStore = new ScopeStore(); 
    var corsService = new CorsService(); 

    factory.UserService = new Registration<IUserService>(resolver => userService); 
    factory.ClientStore = new Registration<IClientStore>(resolver => clientStore); 
    factory.ScopeStore = new Registration<IScopeStore>(resolver => scopeStore); 
    factory.CorsPolicyService = new Registration<ICorsPolicyService>(resolver => corsService); 



    var options = new IdentityServerOptions 
    { 
     SiteName = "Embedded IdentityServer", 
     SigningCertificate = LoadCertificate(), 
     Factory = factory 
    }; 

    app.UseIdentityServer(options); 
} 

Aber im ClientStor und ScopeStore Ich muß Mapping von meinem Client/Scope DB Modell zu IdentityServer3.Core.Models Client/Scope. Wie folgt aus:

ClientStore.cs

public Task<Client> FindClientByIdAsync(string clientId) 
{ 
    var clientFromDb = _db.Clients.SingleOrDefault(x => x.ClientId == clientId); 
    var client = new Client 
    { 
     ClientName = clientFromDb.ClientName, 
     ClientId = clientFromDb.ClientId, 
     AccessTokenType = clientFromDb.AccessTokenType, 
     Enabled = clientFromDb.Enabled, 
     Flow = clientFromDb.Flow, 
     RedirectUris = clientFromDb.RedirectUris.Select(x => x.Uri).ToList(), 
     PostLogoutRedirectUris = clientFromDb.PostLogoutRedirectUris.Select(x => x.Uri).ToList(), 
     AllowedCorsOrigins = clientFromDb.AllowedCorsOrigins.Select(x => x.Origin).ToList(), 
     AllowedScopes = clientFromDb.AllowedScopes.Select(x => x.Scope).ToList(), 
     AllowAccessToAllScopes = clientFromDb.AllowAccessToAllScopes, 
     AccessTokenLifetime = clientFromDb.AccessTokenLifetime 
    }; 

    return Task.FromResult(client); 
} 

Gibt es einen besseren Weg, dies zu tun, wohl wissend, dass meine DB-Modelle sind nur eine Kopie von diesen IdentityServer3.Core.Models?

Antwort

0

factory.UserService = new Registration<IUserService>(resolver => userService); factory.ClientStore = new Registration<IClientStore>(resolver => clientStore); factory.ScopeStore = new Registration<IScopeStore>(resolver => scopeStore); factory.CorsPolicyService = new Registration<ICorsPolicyService>(resolver => corsService);

Diese Art diese Dienste als Singletons registriert. Ich weiß nicht, ob du das willst.

Wenn Sie eine neue Instanz jedes Mal wollen werden sie verwendet, dann verwenden:

factory.UserService = new Registration<IUserService, YourUserService>();

+0

Brummen, nein .. ich will das nicht ... – Stel

+0

Aktualisiert etwas vorschlagen, Sie können wollen. –

Verwandte Themen