protected abstract Task AcquireTokenCoreAsync()

in wwauth/Google.Solutions.WWAuth/Adapters/Adfs/AdfsAdapterBase.cs [162:232]


        protected abstract Task<ISubjectToken> AcquireTokenCoreAsync(
            CancellationToken cancellationToken);

        /// <summary>
        /// Helper class for parsing AD FS responses. 
        /// 
        /// AD FS return errors in HTML format. These HTML pages are 
        /// sometimes not well-formed XML, so it's not possible
        /// to parse them with an XML parser. MSHTML can't be used 
        /// either because it'll conflict with IE ESC which is enabled
        /// on most servers. Thus, use RegEx.
        /// </summary>
        internal class HtmlResponse
        {
            public HtmlResponse(string document)
            {
                document = document
                    .Replace("\n", string.Empty)
                    .Replace("\r", string.Empty);

                this.IsSamlLoginForm = new Regex(@"action=.*SAMLRequest=.*")
                    .IsMatch(document);

                var errorMatch = new Regex(@"(MSIS(\d+):[^<]*)").Match(document);
                if (errorMatch.Success)
                {
                    this.Error = WebUtility.HtmlDecode(errorMatch.Groups[1].Value);
                }

                //
                // Extract input element.
                //
                var input = new Regex("<input.*name\\s*=\\s*\"SAMLResponse\"[^>]*")
                    .Match(document);
                this.IsSamlPostbackForm = input.Success;

                if (this.IsSamlPostbackForm)
                {
                    //
                    // Extract value.
                    //
                    var value = new Regex("value\\s*=\\s*\"([^\"]*)\"").Match(input.Value);
                    if (value.Success)
                    {
                        this.SamlResponse = value.Groups[1].Value;
                    }
                }
            }

            /// <summary>
            /// Check if the page contains a login form for SAML/POST
            /// login.
            /// </summary>
            public bool IsSamlLoginForm { get; }

            /// <summary>
            /// Check if the page contains a postback-form for SAML/POST
            /// login.
            /// </summary>
            public bool IsSamlPostbackForm { get; }

            /// <summary>
            /// Exract SAML response, if any.
            /// </summary>
            public string SamlResponse { get; }

            /// <summary>
            /// Error message, if any.
            /// </summary>
            public string Error { get; }
        }