Hello everyone and thanks for your time.
Sorry for this noobish question but I’m experiencing a bit with this and I don’t quite get what am I missing. I’m trying to send a message to PubSub from my EBS and I’m getting a 400 Bad Request response, so clearly I’m doing something wrong, would you please point my in the right direction?
This is the code I’m using. C# .Net
HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Post, $"https://api.twitch.tv/extensions/message/{streamerID}");
httpRequest.Headers.Add("Authorization", $"Bearer {GenerateToken(streamerID)}");
httpRequest.Headers.Add("Client-Id", "NotARealClientId");
httpRequest.Content = new StringContent("{\"content_type\":\"application/json\", \"message\":\"{\"foo\":\"bar\"}\", \"targets\":[\"broadcast\"]}", System.Text.Encoding.UTF8, "application/json");
var response = httpClient.SendAsync(httpRequest).Result;
This is the GenerateToken code (I’m using a temporary key secret here just in case you want decode the JWT)
const string SECRET_KEY = "lsdkjflk3j345908usdflksjlvcxkjvxlkj23+ASx8q=";
public static string GenerateToken(long channelID)
{
var payload = new Dictionary<string, object>()
{
{"exp", DateTimeOffset.UtcNow.AddDays(1).ToUnixTimeSeconds() },
{"channel_id", channelID },
{"pubsub_perms",
new Dictionary<string, object>()
{
{ "send", new List<string>() { "*" } },
{ "listen", new List<string>() { "*" } }
}
},
{"role", "external" }
};
string token = Jose.JWT.Encode(payload, System.Text.Encoding.UTF8.GetBytes(SECRET_KEY), Jose.JwsAlgorithm.HS512);
return token;
}
Tell me if you guys needs to see another part of the code. This is probably something really easy to fix but I cant figure it out!
Thank you