示例#1
0
        /// <summary>
        /// Only supported in App Model 2.0
        /// </summary>
        /// <param name="scope"></param>
        /// <returns></returns>
        public JObject LoginWithScope(string scope)
        {
            JObject response = new JObject();

            var parameters = new Dictionary <string, string>
            {
                { "response_type", "code" },
                { "client_id", _configuration.ClientId },
                { "redirect_uri", _configuration.RedirectURI },
                { "prompt", "login" },
                { "scope", scope }
            };

            var requestUrl = string.Format("{0}/authorize?{1}", EndPointUrl, BuildQueryString(parameters));

            var dialog = new WebBrowserDialog();

            dialog.OnNavigated((sender, arg) => {
                if (arg.Url.AbsoluteUri.StartsWith(_configuration.RedirectURI))
                {
                    var collection = HttpUtility.ParseQueryString(arg.Url.Query);

                    foreach (var key in collection.AllKeys)
                    {
                        response.Add(key, collection[key]);
                    }

                    dialog.Close();
                }
            });

            dialog.Open(requestUrl);

            return(response);
        }
示例#2
0
        public JObject Login()
        {
            JObject response = new JObject();

            var parameters = new Dictionary <string, string>
            {
                { "response_type", "code id_token" },
                { "client_id", _configuration.ClientId },
                { "nonce", Guid.NewGuid().ToString() },
                { "redirect_uri", _configuration.RedirectURI },
                { "prompt", "login" }
            };

            var requestUrl = string.Format("{0}/authorize?{1}", EndPointUrl, BuildQueryString(parameters));

            var dialog = new WebBrowserDialog();

            dialog.OnNavigated((sender, arg) => {
                if (arg.Url.AbsoluteUri.StartsWith(_configuration.RedirectURI))
                {
                    var browser = sender as WebBrowser;

                    var query = browser.Document.Url.Fragment.TrimStart('#');

                    var collection = HttpUtility.ParseQueryString(query);

                    foreach (var key in collection.AllKeys)
                    {
                        response.Add(key, collection[key]);
                    }

                    // dialog.Close();
                }
            });

            dialog.Open(requestUrl);

            return(response);
        }
示例#3
0
        public void LogOut()
        {
            var dialog = new WebBrowserDialog();

            dialog.Open(string.Format("{0}/logout", EndPointUrl));
        }