AnsweredAssumed Answered

null access_token

Question asked by Srdjan Donevski on Aug 21, 2016
Latest reply on Oct 24, 2016 by

I am trying to create 3rd party app following LTI standard. I am hosing canvas locally on VM. I am using self-signed certificate and set https requests to external tool.

I need token in order to make API calls to Canvas.

I am stuck at the step 3 of getting access_token. Even though I am able to complete step 1 (passing 'scope=/auth/userinfo') and get the code when I try to POST that code in step 3 to /login/oauth2/token along with additional parameters from spec OAuth2 - Canvas LMS REST API Documentation ,  I am getting JSON response in format:


     "access_token": null,

     "user: { "id" : 1,

                   "name": ""



This is my code (c#):

public static string GetAccessToken(string code)


            string retVal = String.Empty;


            string returnUrl = "https:localhost:63333/httphandlers/OAuthComplete.ashx";

            string fullUrl = "http:localhost:3000/login/oauth2/token";

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


            request.Method = "POST";

            var postData = string.Empty;

             // adding post data

            postData = UIHelper.AppendRequestParameter(postData, "client_id", ConfigurationManager.AppSettings[Constants.AppSettingsKeys.DeveloperClientId]);

            postData = UIHelper.AppendRequestParameter(postData, "client_secret", ConfigurationManager.AppSettings[Constants.AppSettingsKeys.DeveloperSecretKey]);

            postData = UIHelper.AppendRequestParameter(postData, "grant_type", "authorization_code");

            postData = UIHelper.AppendRequestParameter(postData, "redirect_uri", HttpUtility.UrlEncode(returnUrl));

            postData = UIHelper.AppendRequestParameter(postData, "code", code);


            var data = Encoding.ASCII.GetBytes(postData.TrimStart('?'));

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

            request.ContentLength = data.Length;

            using (var stream = request.GetRequestStream())


                stream.Write(data, 0, data.Length);


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

            retVal = new StreamReader(response.GetResponseStream()).ReadToEnd();


            return retVal;



It could be something trivial but I am not able to figure it out why I am not able to get access_token.


Thanks in advance,