How to revoke a OAuth Token? [C#]

So, currently I can check if the token is valid and also get some information from it, like the ClientID, UserID, Username and stuff…

What I want now:
I want to instantly revoke it via C# script, if the token is valid, so there is no risk, if you accidently leak the token… But I don’t know how (/._.)/

You’ll need to construct a POST request as shown

With client_id/token as query string arguments

I’ve heard this a lot, but I don’t know how I do that, because I get errors, and I don’t know how to fix them…

Like in this example, I can’t convert the OAuth Token to HttpContent…

My C# is rusty but it should be

"" + client_id + "&token=" + token

All you did there was add the oAuth token to the URL which will generate a 404

That is an perfect “I don’t know why I get an error” example

So fixed or still getting an error?

What error are you getting?

I could do it like the 1st way, but then I’m only sending the client_id

If I do it the 2nd way, he’s asking for an “CancellationToken”

Don’t send it as a “CancellationToken”

Also you don’t have to post screenshots

Just do four spaces and your code

like this


await httpclient.PostAsync("" + client_id + "&token=" + token);

The cancellationToken is nothing to do with oAuth revocation it’s for C# to receive a notification of a cancellation of the request.

var revokeOldToken = await httpclient.PostAsync("", client_id + "&token=" + httpOAuth);

If I do it that way, the client_id + "&token=" + httpOAuth part is an error (convert from string to HttpContent impossible)

This may help

Okay, I don’t get an error anymore, the last thing I have to do, is to substring the client_id from the OAuth validate message and then test it! I will let you know if it works.

I always get this error message: {“status”:400,“message”:“missing client id”}
I’ve split the client Id from the OAuth validation, and post it like you told me… I don’t know what I am doing wrong…

Okay I fixed it with this:

    var splitPoint = content.IndexOf(":", 1);
    var endpoint = content.IndexOf(",", 1);
    var splitClient_id = content.Substring(1);
    splitClient_id = content.Substring(splitPoint + 2, endpoint - splitPoint - 3);

    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, $"{splitClient_id}&token={OAuth_Token}");
    HttpResponseMessage response = await httpclient.SendAsync(request);

Thank you for your help :+1:

1 Like

Glad you got it working!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.