So fügen Sie Refresh -Token in OpenID hinzuC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 So fügen Sie Refresh -Token in OpenID hinzu

Post by Anonymous »

Ich benutze useOpenIdConnectAuthentication
Ich habe den Geltungsbereich als offline_access hinzugefügt, aber wenn sie unten Snippet verwenden, dann context.protocolMessage.refreshtoken . wird nicht gefunden. Kann jemand hier bitte helfen?

Code: Select all

app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{

Scope = "openid profile offline_access User.ReadBasic.All User.Read.All Directory.Read.All",
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = (context) =>
{

string appBaseUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase;

if (redirectUris.Contains(appBaseUrl.ToUpperInvariant()))
{
context.ProtocolMessage.RedirectUri = appBaseUrl + "/";
context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;
}
else
{
context.ProtocolMessage.RedirectUri = redirectUris.First() + "/";
context.ProtocolMessage.PostLogoutRedirectUri = redirectUris.First();
}
return Task.FromResult(0);
},
SecurityTokenValidated = async context =>
{
try
{
ClaimsIdentity claimsIdentity = context.AuthenticationTicket.Identity;

if (claimsIdentity.IsAuthenticated)
{
string userObjectID = claimsIdentity.FindFirst(userObjIdentifier).Value;
if (context.AuthenticationTicket.Properties.ExpiresUtc.HasValue)
{
context.Response.Cookies.Append("AuthTokenExpiryTime", context.AuthenticationTicket.Properties.ExpiresUtc.Value.ToString());
}
var accessToken = context.ProtocolMessage.AccessToken;
if (!string.IsNullOrEmpty(accessToken))
{
claimsIdentity.AddClaim(new System.Security.Claims.Claim("access_token", accessToken));
}

//other code
}
}
catch (Exception ex)
{
Trace.TraceError("Correlation ID: {0}, Exception while getting authentication token in startup.auth.cs. Source: {1}, ExceptionVerbose: {2}",
Trace.CorrelationManager.ActivityId,
ex.Source,
ex.ToString());
throw ex;
}

}
}
});

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post