How to add custom claims

Posted by Community Admin on 04-Aug-2018 19:23

How to add custom claims

All Replies

Posted by Community Admin on 19-May-2014 00:00

Hi,

How to add custom claims with Sitemanager 6.x ?

 I tried to override SitefinityClaimsAuthenticationModule.AuthenticatePrincipalWithCurrentToken(IClaimsPrincipal principal, bool persistent) but it is not marked as virtual.

 Any ideas ?

Posted by Community Admin on 22-May-2014 00:00

Hi Jerome,

You could inherit from the SFClaimsAuthenticationManager and override the Authenticate method. You can create a custom login widget that will use your manager and custom logic. Another option is to try overriding the base ClaimsAuthenticationManager and the same method.

public class MySFClaimsManager : SFClaimsAuthenticationManager
   
       public override Microsoft.IdentityModel.Claims.IClaimsPrincipal Authenticate(string resourceName, Microsoft.IdentityModel.Claims.IClaimsPrincipal incomingPrincipal)
       
           return base.Authenticate(resourceName, incomingPrincipal);
       
   
 
   public class MyClaimsManager : ClaimsAuthenticationManager
   
       public override IClaimsPrincipal Authenticate(string resourceName, IClaimsPrincipal incomingPrincipal)
       
           return base.Authenticate(resourceName, incomingPrincipal);
       
   

Regards,
Nikola Zagorchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 22-May-2014 00:00

Hi Nikola,

 I'm using SecurityManager.AuthenticateUser and SFClaimsAuthenticationManager.Authenticate  is never called.

Overriding SitefinityClaimsAuthenticationModule.AuthenticatePrincipalWithCurrentToken could do the job, but the method is not marked as virtual :

public class MySitefinityClaimsAuthenticationModule : SitefinityClaimsAuthenticationModule

    public override void AuthenticatePrincipalWithCurrentToken(IClaimsPrincipal principal, bool persistent)
   
        ((SitefinityIdentity) principal.Identity).Claims.Add(new Claim("MyClaimType", "MyClaimValue"));
        base.AuthenticatePrincipalWithCurrentToken(IClaimsPrincipal principal, bool persistent)
   


Posted by Community Admin on 27-May-2014 00:00

Hi Jerome,

You should replace the default Claims manager in the web.config to use your custom one. Then, the Authenticate method will be called from your Authentication Manager.

<microsoft.identityModel>
    <service>
       
      <!--<claimsAuthenticationManager type="Telerik.Sitefinity.Security.Claims.SFClaimsAuthenticationManager, Telerik.Sitefinity"/>-->
      <claimsAuthenticationManager type="SitefinityWebApp.MySFClaimsManager, SitefinityWebApp"/>
 
...

Regards,
Nikola Zagorchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 13-Jun-2014 00:00

Fixed after migrating to v7.0.5109.

We can now override SitefinityClaimsAuthenticationModule.AuthenticatePrincipalWithCurrentToken(IClaimsPrincipal principal, bool persistent) and add any custom claims.

Posted by Community Admin on 16-Jun-2014 00:00

Hi Jerome,

I am glad you have resolved the issue. It has been decided to expose this method in the currently penultimate internal build - 7.0.5109.

Regards,
Nikola Zagorchev
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed