0

Ich mag würde wissen, was man konfigurieren, müssen für die automatische Token erneuern, bemerke ich Identity Server Version 3.0 und Javascript-Client UI-Anwendungs ​​bin mitIdentity Server AccessTokenLifetime Eigenschaft und OIDC automaticSilentRenew in C#

Meine Client-Konfiguration ist

new Client 
{ 
    Enabled = true, 
    ClientName = "JS Client", 
    ClientId = "js", 
    Flow = Flows.Implicit, 
    AllowedScopes = new List<string>() { 
     "openid", "profile", "email", "api" 
    }, 

    RedirectUris = new List<string> 
    { 
     "http://localhost:7000/popup.html", 
     "http://localhost:7000/silent-renew.html" 
    }, 

    PostLogoutRedirectUris = new List<string> 
    { 
     "http://localhost:7000/index.html" 
    }, 

    AllowedCorsOrigins = new List<string> 
    { 
     "http://localhost:7000" 
    }, 

    AllowAccessToAllScopes = true, 
    AccessTokenLifetime = 60 
}, 

die aktuelle Einstellung von Client-Wieder Lasten die Webseite auf alle 60 SekundenAccessTokenLifetime = 60

Mein Javascript OIDC Konfiguration ist

var settings = { 
    authority: 'https://localhost:44300', 
    client_id: 'js', 
    popup_redirect_uri: 'http://localhost:7000/popup.html', 
    silent_redirect_uri: 'http://localhost:7000/silent-renew.html', 
    post_logout_redirect_uri: 'http://localhost:7000/index.html', 

    response_type: 'id_token token', 
    scope: 'openid profile email api', 

    accessTokenExpiringNotificationTime: 4, 
    automaticSilentRenew: true, 

    filterProtocolClaims: true 
}; 

Ich weiß nicht, was ist der Zweck der automaticSilentRenew: true, weil alle 60 Sekunden, um es wieder geladen wird. Bitte helfen Sie mir, was der eigentliche Zweck von automaticSilentRenew: true ist? Außerdem helfen Sie mir, was der richtige Weg ist, das Token zu erneuern?

Antwort

0

automaticSilentRenew ist für die stille Authentifizierung. Wenn das Token abläuft, wird die Anforderung an den Server gesendet und das Token wird automatisch ohne Benutzerinteraktion erneuert (es müssen keine Anmeldeinformationen auf der Anmeldeseite eingegeben werden), jedoch mit einer Bedingung, solange die Sitzung auf dem Idsrv aktiv ist.

Wenn diese Option in der Client-Bibliothek aktiviert ist, auf der Client-Seite einige iframes Verifizieren mit Idsrv Sitzung erhalten.

Referenz oidc specs

verbindet, wenn Sie auf der idsrv mit anwendungsspezifischen Logik halten wollen, dann, die beste Wahl ist Profile Implementierung wie unter

public void ConfigureServices(IServiceCollection services) 
    { 

     services.AddIdentityServer(). 
       .AddProfileService<ProfileService>(); 
} 

Implementierung wie

 public class ProfileService : ProfileService<ApplicationUser> 
    { 
     private readonly UserManager<ApplicationUser> userManager; 
     private readonly IUserClaimsPrincipalFactory<ApplicationUser> claimsFactory; 
     //Accessing HTTPContext in ASP.net Core 
     private readonly IHttpContextAccessor httpContextAccessor; 
     public ProfileService(UserManager<ApplicationUser> userManager, IUserClaimsPrincipalFactory<ApplicationUser> claimsFactory, IHttpContextAccessor httpContextAccessor) : base(userManager, claimsFactory) 
     { 
      this.userManager = userManager; 
      this.claimsFactory = claimsFactory; 
      this.httpContextAccessor = httpContextAccessor; 
     } 
     // 
     public override async Task GetProfileDataAsync(ProfileDataRequestContext context) 
     { 
      var sub = context.Subject.Claims.Where(c => c.Type == "sub").FirstOrDefault().Value; 
      var user = await userManager.FindByIdAsync(sub); 
      var principal = await claimsFactory.CreateAsync(user); 
      context.IssuedClaims.AddRange(principal.Claims); 
      context.IssuedClaims.Add(new Claim("Ip", GetRequestIp(httpContextAccessor.HttpContext))); 
     } 
     public override async Task IsActiveAsync(IsActiveContext context) 
     { 
      //Check existing sessions 
      var sub = context.Subject.GetSubjectId(); 
      var user = await userManager.FindByIdAsync(sub); 
      var isactive = user != null; 
      context.IsActive = isactive; 
} 
} 
Verwandte Themen