Api: Missing required parameter grant_type

Created on 22 Oct 2019  Â·  2Comments  Â·  Source: Bungie-net/api

Sorry if this is not the right place to put this. I'm trying to authenticate with the Bungie API, but I'm running into issues getting my access token. I've tried running this through postman as well as code and I'm getting "Missing required parameter grant_type" every time. I've been unable to find anything on Google that has been helpful, and I do not doubt that I am just doing something incorrectly.

I'm using C# in Visual Studio 2019 Community and am using RestSharp to make my request.

Code (X's are just placeholders for actual values):

public static async Task getAccessTokenAsync(string authCode)
{
      byte[] textInBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(GlobalVariables.CLIENTID + ":" + authCode);

      var client = new RestClient("https://www.bungie.net/Platform/App/OAuth/Token/");
      var request = new RestRequest(Method.POST);            
      request.AddHeader("Authorization", "Basic " + System.Convert.ToBase64String(textInBytes));
      request.AddHeader("X-API-Key", "9ca1630154224de7afc00XXXXXXXXX");
      request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
      request.AddParameter("grant_type", "authorization_code", ParameterType.QueryString);
      request.AddParameter("code", authCode, ParameterType.QueryString);
      request.AddParameter("client_id", GlobalVariables.CLIENTID, ParameterType.QueryString);

      IRestResponse response = client.Execute(request);
}

This is the URI it is sending:
https://www.bungie.net/Platform/App/OAuth/Token/?grant_type=authorization_code&code=3796cc629f8e40eXXXXXXXXX&client_id=3XXXX

My application is set to Public for the OAuth Client Type. I'm unsure if my client secret is correct for the Authorization header (I'm using my authorization code as I'm unsure what else it could be). I would greatly appreciate any insight as to what I could be doing wrong.

Most helpful comment

It’s odd that it’s sending your AddParameters as GET parameters rather than as POST body parameters. I don’t know much about .Net, but that’s an odd thing to see there. Could be that Bungie expects a POST body for a POST and is discarding the ?key=value GET ones.

You might try converting to the long form where you construct and send json? I can’t guarantee it’ll help at all, but maybe it’ll uncover some new understanding.

https://stackoverflow.com/a/6313027

On Oct 21, 2019, at 18:04, Vanzen187 notifications@github.com wrote:


Sorry if this is not the right place to put this. I'm trying to authenticate with the Bungie API, but I'm running into issues getting my access token. I've tried running this through postman as well as code and I'm getting "Missing required parameter grant_type" every time. I've been unable to find anything on Google that has been helpful, and I do not doubt that I am just doing something incorrectly.

I'm using C# in Visual Studio 2019 Community and am using RestSharp to make my request.

Code (X's are just placeholders for actual values):

public static async Task getAccessTokenAsync(string authCode)
{
byte[] textInBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(GlobalVariables.CLIENTID + ":" + authCode);

  var client = new RestClient("https://www.bungie.net/Platform/App/OAuth/Token/");
  var request = new RestRequest(Method.POST);            
  request.AddHeader("Authorization", "Basic " + System.Convert.ToBase64String(textInBytes));
  request.AddHeader("X-API-Key", "9ca1630154224de7afc00XXXXXXXXX");
  request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
  request.AddParameter("grant_type", "authorization_code", ParameterType.QueryString);
  request.AddParameter("code", authCode, ParameterType.QueryString);
  request.AddParameter("client_id", GlobalVariables.CLIENTID, ParameterType.QueryString);

  IRestResponse response = client.Execute(request);

}

This is the URI it is sending:
https://www.bungie.net/Platform/App/OAuth/Token/?grant_type=authorization_code&code=3796cc629f8e40eXXXXXXXXX&client_id=3XXXX

My application is set to Public for the OAuth Client Type. I'm unsure if my client secret is correct for the Authorization header (I'm using my authorization code as I'm unsure what else it could be). I would greatly appreciate any insight as to what I could be doing wrong.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

All 2 comments

It’s odd that it’s sending your AddParameters as GET parameters rather than as POST body parameters. I don’t know much about .Net, but that’s an odd thing to see there. Could be that Bungie expects a POST body for a POST and is discarding the ?key=value GET ones.

You might try converting to the long form where you construct and send json? I can’t guarantee it’ll help at all, but maybe it’ll uncover some new understanding.

https://stackoverflow.com/a/6313027

On Oct 21, 2019, at 18:04, Vanzen187 notifications@github.com wrote:


Sorry if this is not the right place to put this. I'm trying to authenticate with the Bungie API, but I'm running into issues getting my access token. I've tried running this through postman as well as code and I'm getting "Missing required parameter grant_type" every time. I've been unable to find anything on Google that has been helpful, and I do not doubt that I am just doing something incorrectly.

I'm using C# in Visual Studio 2019 Community and am using RestSharp to make my request.

Code (X's are just placeholders for actual values):

public static async Task getAccessTokenAsync(string authCode)
{
byte[] textInBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(GlobalVariables.CLIENTID + ":" + authCode);

  var client = new RestClient("https://www.bungie.net/Platform/App/OAuth/Token/");
  var request = new RestRequest(Method.POST);            
  request.AddHeader("Authorization", "Basic " + System.Convert.ToBase64String(textInBytes));
  request.AddHeader("X-API-Key", "9ca1630154224de7afc00XXXXXXXXX");
  request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
  request.AddParameter("grant_type", "authorization_code", ParameterType.QueryString);
  request.AddParameter("code", authCode, ParameterType.QueryString);
  request.AddParameter("client_id", GlobalVariables.CLIENTID, ParameterType.QueryString);

  IRestResponse response = client.Execute(request);

}

This is the URI it is sending:
https://www.bungie.net/Platform/App/OAuth/Token/?grant_type=authorization_code&code=3796cc629f8e40eXXXXXXXXX&client_id=3XXXX

My application is set to Public for the OAuth Client Type. I'm unsure if my client secret is correct for the Authorization header (I'm using my authorization code as I'm unsure what else it could be). I would greatly appreciate any insight as to what I could be doing wrong.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Thank you so much, it didn't even click that it was sending those as GET parameters, I've been stuck on this for longer than I care to admit. Worked immediately as soon as I changed it over to POST.

For anybody else who finds themselves here, this is the updated code:

public static async Task getAccessTokenAsync(string authCode)
{
      var client = new RestClient("https://www.bungie.net/Platform/App/OAuth/Token/");
      var request = new RestRequest(Method.POST);            
      request.AddHeader("X-API-Key", "9ca1630154224de7afc00XXXXXXXXX");
      request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
      request.AddParameter("grant_type", "authorization_code");
      request.AddParameter("code", authCode);
      request.AddParameter("client_id", GlobalVariables.CLIENTID);

      IRestResponse response = client.Execute(request);
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nathabba picture nathabba  Â·  3Comments

as-com picture as-com  Â·  3Comments

andyschott picture andyschott  Â·  3Comments

lax20attack picture lax20attack  Â·  4Comments

justrealmilk picture justrealmilk  Â·  3Comments