コード例 #1
0
        public static async Task <SalesforceTokenResponse> GetTokenAsync(string loginUrl, SalesforceApiTokenRequest tokenRequest)
        {
            var post    = $"grant_type=password&client_id={tokenRequest.ConsumerKey}&client_secret={tokenRequest.ConsumerSecret}&username={WebUtility.UrlEncode(tokenRequest.Username)}&password={tokenRequest.Password}{tokenRequest.Token}";
            var http    = new HttpClient();
            var payload = new StringContent(post);

            payload.Headers.ContentType = new MediaTypeHeaderValue(@"application/x-www-form-urlencoded");
            var getToken = http.PostAsync(loginUrl, payload);

            return(JsonConvert.DeserializeObject <SalesforceTokenResponse>(await(await getToken).Content.ReadAsStringAsync()));
        }
コード例 #2
0
 public static Task <SalesforceTokenResponse> GetTokenAsync(SalesforceApiTokenRequest tokenRequest) =>
 GetTokenAsync("https://login.salesforce.com/services/oauth2/token", tokenRequest);