<commit_before>﻿using System;
using System.Management.Automation;
using SharePointPnP.PowerShell.CmdletHelpAttributes;
using System.Net;

namespace SharePointPnP.PowerShell.Commands
{
    [Cmdlet(VerbsCommon.Get, "SPOAuthenticationRealm")]
    [CmdletHelp("Gets the authentication realm for the current web", 
        Category = CmdletHelpCategory.Base)]
    [CmdletExample(
        Code = @"PS:> Get-SPOAuthenticationRealm", 
        Remarks = @"This will get the authentication realm for the current connected site",
        SortOrder = 1)]
    [CmdletExample(
        Code = @"PS:> Get-SPOAuthenticationRealm -Url https://contoso.sharepoint.com",
        Remarks = @"This will get the authentication realm for https://contoso.sharepoint.com",
        SortOrder = 2)]
    public class GetAuthenticationRealm : SPOCmdlet
    {

        [Parameter(Mandatory = false, Position=0, ValueFromPipeline=true, HelpMessage = "Specifies the URL of the site")]
        public string Url;

        protected override void ProcessRecord()
        {
            if(string.IsNullOrEmpty(Url))
            {
                Url = ClientContext.Url;
            }
            WebRequest request = WebRequest.Create(new Uri(Url) + "/_vti_bin/client.svc");
            request.Headers.Add("Authorization: Bearer ");

            try
            {
                using (request.GetResponse())
                {
                }
            }
            catch (WebException e)
            {
                if (e.Response == null)
                {
                }

                var bearerResponseHeader = e.Response.Headers["WWW-Authenticate"];
                if (string.IsNullOrEmpty(bearerResponseHeader))
                {
                }

                const string bearer = "Bearer realm=\"";
                var bearerIndex = bearerResponseHeader.IndexOf(bearer, StringComparison.Ordinal);
                if (bearerIndex < 0)
                {
                }

                var realmIndex = bearerIndex + bearer.Length;

                if (bearerResponseHeader.Length >= realmIndex + 36)
                {
                    var targetRealm = bearerResponseHeader.Substring(realmIndex, 36);

                    Guid realmGuid;

                    if (Guid.TryParse(targetRealm, out realmGuid))
                    {
                        WriteObject(targetRealm);
                    }
                }
            }
        }


    }
}<commit_msg>Removed redundant code<commit_after>﻿using System;
using System.Management.Automation;
using SharePointPnP.PowerShell.CmdletHelpAttributes;
using System.Net;

namespace SharePointPnP.PowerShell.Commands
{
    [Cmdlet(VerbsCommon.Get, "SPOAuthenticationRealm")]
    [CmdletHelp("Gets the authentication realm for the current web", 
        Category = CmdletHelpCategory.Base)]
    [CmdletExample(
        Code = @"PS:> Get-SPOAuthenticationRealm", 
        Remarks = @"This will get the authentication realm for the current connected site",
        SortOrder = 1)]
    [CmdletExample(
        Code = @"PS:> Get-SPOAuthenticationRealm -Url https://contoso.sharepoint.com",
        Remarks = @"This will get the authentication realm for https://contoso.sharepoint.com",
        SortOrder = 2)]
    public class GetAuthenticationRealm : SPOCmdlet
    {

        [Parameter(Mandatory = false, Position=0, ValueFromPipeline=true, HelpMessage = "Specifies the URL of the site")]
        public string Url;

        protected override void ProcessRecord()
        {
            if(string.IsNullOrEmpty(Url))
            {
                Url = ClientContext.Url;
            }
            WebRequest request = WebRequest.Create(new Uri(Url) + "/_vti_bin/client.svc");
            request.Headers.Add("Authorization: Bearer ");

            try
            {
                using (request.GetResponse())
                {
                }
            }
            catch (WebException e)
            {
                var bearerResponseHeader = e.Response.Headers["WWW-Authenticate"];

                const string bearer = "Bearer realm=\"";
                var bearerIndex = bearerResponseHeader.IndexOf(bearer, StringComparison.Ordinal);

                var realmIndex = bearerIndex + bearer.Length;

                if (bearerResponseHeader.Length >= realmIndex + 36)
                {
                    var targetRealm = bearerResponseHeader.Substring(realmIndex, 36);

                    Guid realmGuid;

                    if (Guid.TryParse(targetRealm, out realmGuid))
                    {
                        WriteObject(targetRealm);
                    }
                }
            }
        }


    }
}
{'fraction_non_alphanumeric': 0.0890835291604358, 'fraction_numerical': 0.003204443494979705, 'mean_word_length': 1.7348130841121496, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3505001', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1170, 'n_words': 262}