Esempio n. 1
0
        public async Task <string> ReceiveToken(string code = null, string state = null)
        {
            if (!string.IsNullOrEmpty(code) && !string.IsNullOrEmpty(state))
            {
                var    tokenUri = CreateOAuthTokenRequestUri(code);
                string result   = null;

                using (var http = new HttpClient())
                {
                    var c       = tokenUri.Query.Remove(0, 1);
                    var content = new StringContent(c);
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                    var resp = await http.PostAsync(new Uri("https://login.live.com/oauth20_token.srf"), content);

                    result = await resp.Content.ReadAsStringAsync();
                }

                dynamic obj = JsonConvert.DeserializeObject(result);
                _creds.AddToken(state, obj.access_token.ToString());
                return("Done, thanks!");
            }
            return("Something went wrong - please try again!");
        }