Exemplo n.º 1
0
        // アクセストークンの取得
        public async Task <AccessTokenJson> getTokenJson(string host, string client_id, string client_sec, string user_id, string password)
        {
            var data     = new AccessTokenJson();
            var postData = new List <KeyValuePair <string, string> >();

            postData.Add(new KeyValuePair <string, string>("client_id", client_id));
            postData.Add(new KeyValuePair <string, string>("client_secret", client_sec));
            postData.Add(new KeyValuePair <string, string>("grant_type", "password"));
            postData.Add(new KeyValuePair <string, string>("username", user_id));
            postData.Add(new KeyValuePair <string, string>("password", password));
            postData.Add(new KeyValuePair <string, string>("scope", DefaultValue.MSTDN_SCOPE));  // こっちはscope 上はscopes なんのトラップだ
            var content = new FormUrlEncodedContent(postData);
            var url     = "https://" + host + DefaultValue.MSTDN_TOKENPATH;

            try {
                var response = await client.PostAsync(url, content);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    data = JsonConvert.DeserializeObject <AccessTokenJson>(json);
                }
            } catch (Exception ex) {
                throw ex;
            }
            return(data);
        }
Exemplo n.º 2
0
        private void setAccessToken(AccessSQLite db, AccessTokenJson token)
        {
            var tok = new AccessToken();

            tok.Host  = DefaultValue.MSTDN_HOST;
            tok.Token = token.access_token;
            db.DeleteAccessTokenMaster();
            db.InsertAccessTokenMaster(tok);
        }