Request
  • Post

  • https://login.microsoftonline.com/ec8933c6-cfb2-4dd9-bfc9-621cde1dea8f/oauth2/token

  • x-www-form-urlencoded

  • xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx


    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


    client_credentials


    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx


    Note: All Request Body Parameters will be provided by Westcon through mail communication

Response

{

   "token_type": "Bearer",

   "expires_in": "3600",

   "ext_expires_in": "3600",

   "expires_on": "1562587331",

   "not_before": "1562583431",

   "resource": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",

   "access_token": "xxxxxxxxxxxxxxxxx...xxxxxxxxxxxxxx"

}

.NET Code Example

 

private object GetAccessToken()

        {

            //throw new NotImplementedException();

            string uri = "https://login.microsoftonline.com/ec8933c6-cfb2-4dd9-bfc9-621cde1dea8f/oauth2/token";

            var client_id = ConfigurationManager.AppSettings["client_id"];

            var client_secret = ConfigurationManager.AppSettings["client_secret"];

            var resource = ConfigurationManager.AppSettings["resource"];

 

            string body = "client_id=" + client_id + "&client_secret=" + client_secret + "&grant_type=client_credentials&resource=" + resource;

            AccessTokens tokens;

            var request = (HttpWebRequest)WebRequest.Create(uri);

            request.Method = "POST";

            request.Accept = "application/json";

            request.ContentType = "application/x-www-form-urlencoded";

 

            request.ContentLength = body.Length;

 

            using (Stream requestStream = request.GetRequestStream())

            {

                StreamWriter writer = new StreamWriter(requestStream);

                writer.Write(body);

                writer.Close();

            }

 

            var response = (HttpWebResponse)request.GetResponse();

 

            using (Stream responseStream = response.GetResponseStream())

            {

                var reader = new StreamReader(responseStream);

                string json = reader.ReadToEnd();

                reader.Close();

                tokens = JsonConvert.DeserializeObject(json, typeof(AccessTokens)) as AccessTokens;

            }

 

            return tokens.AccessToken;

        }