Search code examples
c#sharepointweb-parts

How do we get the current Authentication Mode in SharePoint using C#


I have a sharepoint site which has different authentication options available for users to login like Windows, Trusted SAML etc

How can i determine which is the authentication mode of the current request?

I have tried the "SPSecurity.AuthenticationMode" but its value is always forms.


Solution

  • You would need to get it via SPOriginalIssuerType Property

    var localClaimManager = SPClaimProviderManager.Local;
                    if (localClaimManager != null)
                    {
                        var issuerType=SPOriginalIssuers.GetIssuerType(localClaimManager.DecodeClaim(SPContext.Current.Web.CurrentUser.LoginName).OriginalIssuer);
                        //Write your logic based on the issuerType received
    //https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.administration.claims.sporiginalissuertype?view=sharepoint-server
    
                    }