public static string ToJsonWebTokenString()

in CredentialProvider.Microsoft/Util/ExtensionMethods.cs [95:114]


        public static string ToJsonWebTokenString(this string accessToken)
        {
            // Effictively this splits by '.' and converts from a base-64 encoded string.  Splitting creates new strings so this just calculates
            // a substring instead to reduce memory overhead.
            int start = accessToken.IndexOf(".", StringComparison.Ordinal) + 1;

            if (start < 0)
            {
                return null;
            }

            int length = accessToken.IndexOf(".", start, StringComparison.Ordinal) - start;

            return start > 0 && length < accessToken.Length
                ? Encoding.UTF8.GetString(
                    Convert.FromBase64String(
                        accessToken.Substring(start, length)
                            .PadRight(length + (length % 4), '=')))
                : null;
        }