3

Ich habe einen IdentityServer4 Server mit einer benutzerdefinierten Identität Ressource:Wie wird die benutzerdefinierte Identitätsressource Claim für den hybriden Flow-Client gefüllt?

new Client 
       { 
        ClientId = "client.mvc", 
        ClientName = "MVC Core Client", 
        AllowedGrantTypes = GrantTypes.Hybrid, 
        ... 
        AllowedScopes = 
        { 
         IdentityServerConstants.StandardScopes.OpenId, 
         IdentityServerConstants.StandardScopes.Profile, 
         "custom.profile" 
        }, 
:

new IdentityResource 
{ 
    Name = "custom.profile", 
    UserClaims = new[] { "location" } 
} 

Diese Ressource durch den Benutzer eines ASP.NET MVC-Client verbindet wiht OIDC Hybridstrom und keine Zustimmung Seite verwendet wird,

Anmeldung manuell in <idsrv>/Login/DoLogin getan:

public async Task<IActionResult> DoLogin(LoginInputModel model) 
     { 
      if (ModelState.IsValid) 
      { 
       if (model.Username == "test.user" && model.Password == "password") 
       { 
        Guid userId = new Guid("8da49efb-a1aa-4253-bb7f-56cc6c532b78"); 

        await HttpContext.Authentication.SignInAsync(userId.ToString(), model.Username); 

        if (_interaction.IsValidReturnUrl(model.ReturnUrl)) 
        { 
         return Redirect(model.ReturnUrl); 
        } 

        return Redirect("~/"); 
       } 

       ModelState.AddModelError("", "Invalid username or password."); 
      } 

Meine Frage ist, wie/wo tun bevöl ich dieses "location "Wert des Bereichs" custom.profile "für den Benutzer?

Antwort

1

Sie müssen im Wesentlichen die GetProfileDataAsync Methode auf dem IProfileService Dienst implementieren, um einige Ansprüche hinzuzufügen.

So in Start sicherstellen, dass Sie so etwas wie:

identityServerBuilder.Services.AddScoped<IProfileService, ProfileService>(); 

Und dann in Ihrer ProfileService Klasse etwas wie folgt aus:

public Task GetProfileDataAsync(ProfileDataRequestContext context) { 
    context.IssuedClaims.Add(new Claim()); //Your claims(s) 
} 
+3

, dass fast richtig ist. Sie sollten sich zuerst die Forderungsarten der Anfrage ansehen. Sie werden als Teil des Kontexts weitergegeben. – leastprivilege

+0

@leastprivilege: Wenn ich mich nicht irre, müssen Sie IProfileService und den call/connect/userinfo-Endpunkt auf dem Client implementieren (wie im OnAuthorizationCodeReceived-Ereignis), um benutzerdefinierte Ansprüche zu erhalten, und Sie können keine benutzerdefinierten Ansprüche auf der Serverseite in IdentityServer4 hinzufügen Zuschüsse, bin ich richtig? – dstr

Verwandte Themen