Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RememberMe claim to current identity principal. #18476

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,14 @@ public static class AbpClaimTypes
/// Default: "impersonator_username".
/// </summary>
public static string ImpersonatorUserName { get; set; } = "impersonator_username";

/// <summary>
/// Default: "picture".
/// </summary>
public static string Picture { get; set; } = "picture";

/// <summary>
/// Default: "remember_me".
/// </summary>
public static string RememberMe { get; set; } = "remember_me";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
Expand All @@ -12,6 +13,7 @@
using OpenIddict.Server.AspNetCore;
using Volo.Abp.AspNetCore.Security;
using Volo.Abp.OpenIddict.ViewModels.Authorization;
using Volo.Abp.Security.Claims;

namespace Volo.Abp.OpenIddict.Controllers;

Expand Down Expand Up @@ -123,6 +125,12 @@ public virtual async Task<IActionResult> HandleAsync()
case OpenIddictConstants.ConsentTypes.Explicit when authorizations.Any() && !request.HasPrompt(OpenIddictConstants.Prompts.Consent):
var principal = await SignInManager.CreateUserPrincipalAsync(user);

if (result.Properties != null && result.Properties.IsPersistent)
{
var claim = new Claim(AbpClaimTypes.RememberMe, true.ToString()).SetDestinations(OpenIddictConstants.Destinations.AccessToken);
principal.Identities.FirstOrDefault()?.AddClaim(claim);
}

// Note: in this sample, the granted scopes match the requested scope
// but you may want to allow the user to uncheck specific scopes.
// For that, simply restrict the list of scopes before calling SetScopes.
Expand Down Expand Up @@ -216,6 +224,13 @@ public virtual async Task<IActionResult> HandleCallbackAsync()

var principal = await SignInManager.CreateUserPrincipalAsync(user);

var result = await HttpContext.AuthenticateAsync(IdentityConstants.ApplicationScheme);
if (result.Succeeded && result.Properties != null && result.Properties.IsPersistent)
{
var claim = new Claim(AbpClaimTypes.RememberMe, true.ToString()).SetDestinations(OpenIddictConstants.Destinations.AccessToken);
principal.Identities.FirstOrDefault()?.AddClaim(claim);
}

// Note: in this sample, the granted scopes match the requested scope
// but you may want to allow the user to uncheck specific scopes.
// For that, simply restrict the list of scopes before calling SetScopes.
Expand Down