コード例 #1
0
        public bool GetAccessToken(string verificationCode = null)
        {
            Config.Tokens.Clear();

            foreach (MinusScope scope in Enum.GetValues(typeof(MinusScope)))
            {
                string url = string.Format("{0}/oauth/token?grant_type=password&client_id={1}&client_secret={2}&scope={3}&username={4}&password={5}",
                                           URL_HOST,
                                           AuthInfo.ConsumerKey,
                                           AuthInfo.ConsumerSecret,
                                           scope.ToString(),
                                           this.UserName,
                                           this.Password);

                string         response = SendGetRequest(url);
                MinusAuthToken mat      = JsonConvert.DeserializeObject <MinusAuthToken>(response);

                if (mat != null)
                {
                    Config.Tokens.Add(mat);
                }
            }

            return(true);
        }
コード例 #2
0
        public void RefreshAccessTokens()
        {
            List <MinusAuthToken> newTokens = new List <MinusAuthToken>();

            foreach (MinusScope scope in Enum.GetValues(typeof(MinusScope)))
            {
                string url = string.Format("{0}/oauth/token?grant_type=refresh_token&client_id={1}&client_secret={2}&scope={3}&refresh_token={4}",
                                           URL_HOST, AuthInfo.ConsumerKey, AuthInfo.ConsumerSecret, scope.ToString(), Config.GetToken(scope).refresh_token);

                string         response = SendGetRequest(url);
                MinusAuthToken mat      = JsonConvert.DeserializeObject <MinusAuthToken>(response);

                if (mat != null)
                {
                    newTokens.Add(mat);
                }
            }

            Config.Tokens = newTokens;
        }