Esempio n. 1
0
        //TODO check token
        /// <summary>
        /// Get token using blizzard login credentials => authorization code
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task <BearerToken> GetTokenWithAuthenticationCode(string code)
        {
            string path      = "oauth/token";
            var    authToken = Encoding.ASCII.GetBytes($"{ConfigurationManager.AppSettings["client_id"]}:{ConfigurationManager.AppSettings["client_secret"]}");
            AuthenticationHeaderValue             authHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken));
            List <KeyValuePair <string, string> > content    = new List <KeyValuePair <string, string> >();

            content.Add(new KeyValuePair <string, string>("grant_type", "authorization_code"));
            content.Add(new KeyValuePair <string, string>("scope", "wow.profile openid"));
            content.Add(new KeyValuePair <string, string>("redirect_uri", "https://localhost:44380/Account/Authorize"));
            content.Add(new KeyValuePair <string, string>("code", code));
            content.Add(new KeyValuePair <string, string>("region", "eu"));

            try
            {
                string response = await SendPost(true, path, content, authHeader);

                BearerToken token = JsonConvert.DeserializeObject <BearerToken>(response);
                token.SetExpirationDate();
                instance.token = token;
                return(token);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(null);
        }
Esempio n. 2
0
        //TODO check token
        //
        /// <summary>
        /// Get token using developer client code+secret
        /// </summary>
        /// <returns></returns>
        public async Task <BearerToken> GetTokenWithClientCredentials()
        {
            string path      = "oauth/token";
            var    authToken = Encoding.ASCII.GetBytes($"{ConfigurationManager.AppSettings["client_id"]}:{ConfigurationManager.AppSettings["client_secret"]}");
            AuthenticationHeaderValue             authHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authToken));
            List <KeyValuePair <string, string> > content    = new List <KeyValuePair <string, string> >();

            content.Add(new KeyValuePair <string, string>("grant_type", "client_credentials"));

            try
            {
                string response = await SendPost(true, path, content, authHeader);

                BearerToken token = JsonConvert.DeserializeObject <BearerToken>(response);
                token.SetExpirationDate();
                instance.token = token;
                return(token);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(null);
        }