Ejemplo n.º 1
0
        /// <summary>
        /// Adds a relayState query string parameter.
        /// </summary>
        /// <param name="values">A dictionary containing the name-value pairs of the relayState parameter.</param>
        /// <returns>The <see cref="SamlUrlBuilder"/>.</returns>
        public SamlUrlBuilder WithRelayState(System.Collections.Generic.IDictionary <string, string> values)
        {
            // Note to future maintainers:
            // It is important to use correct casing! This parameter must use PascalCase (i.e. RelayState),
            // otherwise it will not be passed on correctly. See https://github.com/auth0/auth0.net/issues/186
            AddQueryString("RelayState", string.Join("&", values.Select(kvp => $"{kvp.Key}={kvp.Value}")));

            return(this);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a relayState query string parameter.
        /// </summary>
        /// <param name="values">A dictionary containing the name-value pairs of the relayState parameter.</param>
        /// <returns>The <see cref="SamlUrlBuilder"/>.</returns>
        public SamlUrlBuilder WithRelayState(System.Collections.Generic.IDictionary <string, string> values)
        {
            AddQueryString("relayState", string.Join("&", values.Select(kvp => $"{kvp.Key}={kvp.Value}")));

            return(this);
        }
Ejemplo n.º 3
0
            /// <summary>
            /// Whether the UIWebView should begin loading data.
            /// </summary>
            /// <returns><c>true</c>, if start load was shoulded, <c>false</c> otherwise.</returns>
            /// <param name="webView">Web view.</param>
            /// <param name="request">Request.</param>
            /// <param name="navigationType">Navigation type.</param>
            public override bool ShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
            {
                NSUrl nsUrl = request.Url;

                string msg = null;

#if DEBUG
                StringBuilder sb = new StringBuilder();
                sb.AppendLine($"UIWebViewDelegate.ShouldStartLoad ");
                sb.AppendLine($"        nsUrl.AbsoluteString = {nsUrl.AbsoluteString}");
                sb.AppendLine($"        WebViewConfiguration.IOS.UserAgent = {WebViewConfiguration.IOS.UserAgent}");
                System.Diagnostics.Debug.WriteLine(sb.ToString());
#endif

                WebAuthenticator         wa  = null;
                WebRedirectAuthenticator wra = null;

                wa  = this.controller.authenticator as WebAuthenticator;
                wra = this.controller.authenticator as WebRedirectAuthenticator;

#if DEBUG
                if (wa != null)
                {
                    msg = String.Format("WebAuthenticatorController.authenticator as WebAuthenticator");
                    System.Diagnostics.Debug.WriteLine(msg);
                }
                if (wra != null)
                {
                    msg = String.Format("WebAuthenticatorController.authenticator as WebRedirectAuthenticator");
                    System.Diagnostics.Debug.WriteLine(msg);
                }

                msg = String.Format("WebAuthenticatorController.ShouldStartLoad {0}", nsUrl.AbsoluteString);
                System.Diagnostics.Debug.WriteLine(msg);
#endif

                bool is_loadable_url = false;
                if (nsUrl != null && !controller.authenticator.HasCompleted)
                {
                    Uri url;
                    if (Uri.TryCreate(nsUrl.AbsoluteString, UriKind.Absolute, out url))
                    {
                        string host   = url.Host.ToLower();
                        string scheme = url.Scheme;

#if DEBUG
                        msg = String.Format("WebAuthenticatorController.ShouldStartLoad {0}", url.AbsoluteUri);
                        System.Diagnostics.Debug.WriteLine(msg);
                        msg = string.Format("                          Host   = {0}", host);
                        System.Diagnostics.Debug.WriteLine(msg);
                        msg = string.Format("                          Scheme = {0}", scheme);
                        System.Diagnostics.Debug.WriteLine(msg);
#endif

                        if (host == "localhost" || host == "127.0.0.1" || host == "::1")
                        {
                            is_loadable_url = false;
                            this.controller.DismissViewControllerAsync(true);
                        }
                        else
                        {
                            is_loadable_url = true;
                        }
                        // COSMOS

                        if (request.Body != null)
                        {
                            Encoding encoding = Encoding.UTF8;

                            if (request.Headers != null && request.Headers.ContainsKey(new NSString("Content-Type")))
                            {
                                encoding = WebEx.GetEncodingFromContentType(request.Headers[new NSString("Content-Type")].ToString());
                            }
                            byte[] dataBytes = new byte[request.Body.Length];
                            System.Runtime.InteropServices.Marshal.Copy(request.Body.Bytes, dataBytes, 0, Convert.ToInt32(request.Body.Length));
                            string bodyString = encoding.GetString(dataBytes);
                            System.Collections.Generic.IDictionary <string, string> formParams = WebEx.FormDecode(bodyString);
                            var concatenatedParameters = formParams.Select(pair =>
                                                                           $"{System.Net.WebUtility.UrlEncode(pair.Key)}={System.Net.WebUtility.UrlEncode(pair.Value)}");

                            var query     = string.Join("&", concatenatedParameters);
                            var uriString = string.IsNullOrEmpty(url.Query) ?
                                            url.OriginalString + $"?{query}" :
                                            url.OriginalString + $"&{query}";
                            url = new Uri(uriString);
                        }
                        //
                        controller.authenticator.OnPageLoading(url);
                    }
                }

                if (wra != null)
                {
                    // TODO: class refactoring
                    // OAuth2Authenticator is WebRedirectAuthenticator wra
                    wra.IsLoadableRedirectUri = is_loadable_url;
                    return(wra.IsLoadableRedirectUri);
                }
                else if (wa != null)
                {
                    // TODO: class refactoring
                    // OAuth1Authenticator is WebRedirectAuthenticator wra
                    return(is_loadable_url);
                }

                return(false);
            }