How do I get an OAuth 2.0 authentication token in C#

后端 未结 7 1163
借酒劲吻你
借酒劲吻你 2020-12-02 11:15

I have these settings:

  • Auth URL (which happens to be a \"https://login.microsoftonline.com/...\") if that helps.
  • Access Token URL \"https://service.en
相关标签:
7条回答
  • 2020-12-02 11:55

    This example get token thouth HttpWebRequest

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(pathapi);
            request.Method = "POST";
            string postData = "grant_type=password";
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] byte1 = encoding.GetBytes(postData);
    
            request.ContentType = "application/x-www-form-urlencoded";
    
            request.ContentLength = byte1.Length;
            Stream newStream = request.GetRequestStream();
            newStream.Write(byte1, 0, byte1.Length);
    
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;            
            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                getreaderjson = reader.ReadToEnd();
            }
    
    0 讨论(0)
提交回复
热议问题