示例#1
0
        /// <summary>
        /// Written by Jonas
        /// You will now request a Access Token from Xena's Authorization Server.
        /// You build a encoded URL and send it to Xena's Authorization Server.
        /// Xena's Authorization Server sends a long string back, this is your Access Token!
        /// You assign it to your varible, and it is now ready to be shipped with any Xena's API calls ;)
        /// </summary>
        public static string AccessToken(Xena xena)
        {
            List <KeyValuePair <string, string> > keyValuePairs = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("code", xena.id_code),
                new KeyValuePair <string, string>("client_id", "2e64617f-dc5d-4983-ba27-7dcdb2ed5510.apps.xena.biz"),
                new KeyValuePair <string, string>("redirect_uri", "http://xenabudgetmanager.azurewebsites.net/"),
                new KeyValuePair <string, string>("client_secret", ConfigurationManager.AppSettings["client_secret"]),
                new KeyValuePair <string, string>("grant_type", "authorization_code"),
                new KeyValuePair <string, string>("response_mode", "form_post"),
                new KeyValuePair <string, string>("json", "true")
            };

            FormUrlEncodedContent content = new FormUrlEncodedContent(keyValuePairs);

            using (HttpClient httpClient = new HttpClient())
            {
                HttpResponseMessage response = httpClient.PostAsync("https://login.xena.biz/connect/token?", content).Result;

                string result = response.Content.ReadAsStringAsync().Result;

                JObject jObject = JObject.Parse(result);

                xena.access_token = jObject["access_token"].ToString();
                return(xena.access_token);
            }
        }
示例#2
0
        public ActionResult Index(Xena xena)
        {
            xena.id_code      = Request["code"];
            xena.access_token = XenaLogic.AccessToken(xena);

            Session["access_token"] = xena.access_token;
            Session["loggedIn"]     = true;

            List <JToken> jTokenList = XenaLogic.CallXena(Session["access_token"].ToString(),
                                                          "User/XenaUserMembership?ForceNoPaging=true&Page=0&PageSize=10&ShowDeactivated=false");

            Session["userName"] = jTokenList[0]["ResourceName"].ToString();

            ViewBag.Token = xena.access_token; // Debug

            //return View(); // Debug
            return(RedirectToAction("Fiscals"));
        }