Browse Source

Merge pull request #18476 from abpframework/RememberMe

Add `RememberMe` claim to current identity principal.
pull/18637/head
Halil İbrahim Kalkan 2 years ago
committed by GitHub
parent
commit
d353d6ef64
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/AbpClaimTypes.cs
  2. 15
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AuthorizeController.cs

7
framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/AbpClaimTypes.cs

@ -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";
}

15
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/AuthorizeController.cs

@ -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;
@ -12,6 +13,7 @@ using OpenIddict.Abstractions;
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;
@ -123,6 +125,12 @@ public class AuthorizeController : AbpOpenIdDictControllerBase
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.
@ -216,6 +224,13 @@ public class AuthorizeController : AbpOpenIdDictControllerBase
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.

Loading…
Cancel
Save