C
Join ServerC#
help
How do i do the following with AuthenticationHeaderValue class?
MMemw10/11/2022
So i basically wanna auth to github api with the basic authentication the string i'm inputing is actually
user:token
, but it won't work either, here is what i tried so far.requestClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(Client.Env["GITCREDS"])));
Client.Env["GITCREDS"]
actually returns the string.
MMemw10/11/2022
i always get 403 because for some reason i'm not able to auth, i want to remark that with insomnia these creds work
YYawnder10/11/2022
@Memw Have you tried breaking it down into steps and see what fails rather than embedding 3 method calls and an indexer?
MMemw10/11/2022
yeah i logged Convert.ToBase64String(thing) before and it gave a weird string, i'm guessing comming from Encoding.ASCII.GetBytes()
YYawnder10/11/2022
@Memw And when you compared that value from the one shows encoded in the tool you took the screenshot from?
MMemw10/11/2022
What do you mean by comparing? it is different that's all i know
YYawnder10/11/2022
Well you don't see keen on sharing any details so good luck!
MMemw10/11/2022
i do
MMemw10/11/2022
but what details do you want me to share
MMemw10/11/2022
i didn't understand the question correctly, i'm not native english, so sorry for that
YYawnder10/11/2022
Alright. Since you shouldn't share a password, try with username
abc
and password def1%&
and give the values of when extracted from the setting and when encoded. I'll compare to what I have on my side.MMemw10/11/2022
With this input
The output is
Encoding.ASCII.GetBytes("abc:def1%&")
The output is
YWJjOmRlZjElJg==
MMemw10/11/2022
@Yawnder
YYawnder10/11/2022
Same value as I have...
MMemw10/11/2022
i'm actually doing this
requestClient being an HttpClient
requestClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("abc:def1%&")));
Console.WriteLine(requestClient.DefaultRequestHeaders.Authorization.Parameter);
requestClient being an HttpClient
YYawnder10/11/2022
Are you certain your
Client.Env["GITCREDS"]
returns the proper value?MMemw10/11/2022
i logged it and yeah i'm pretty sure it does
YYawnder10/11/2022
Humn...
MMemw10/11/2022

MMemw10/11/2022
i can't share the full thing but yeah it does log the thing
MMemw10/11/2022
and the thing is always
Exception: Response status code does not indicate success: 403 (Forbidden).
MMemw10/11/2022
as if there were no credentials or something
YYawnder10/11/2022
Could that be it?

YYawnder10/11/2022
Wait, 403 isn't that actually
MMemw10/11/2022
I'm using username and token
YYawnder10/11/2022
403 means the authentication is working fine, but authorization isn't.
MMemw10/11/2022
and with insomnia http client it just gives me 200
YYawnder10/11/2022
For the same endpoint?
MMemw10/11/2022
yup
MMemw10/11/2022
maybe the way is not user:token? and other thing?
MMemw10/11/2022
or github doesn't want base64? but with raw string doesn't let me either
MMemw10/11/2022
so i'm kinda lost on that
YYawnder10/11/2022
No idea. If it works with insomnia, you could inspect using Fiddler and see what is different.
MMemw10/11/2022
Oh.
MMemw10/11/2022

MMemw10/11/2022
User Agent
YYawnder10/11/2022
But why does the same credentials work for the same endpoint using another client?
MMemw10/11/2022
Because insomnia maybe sends the user agent, i'm not sure what does it send but i'm very sure it does send the user agent
YYawnder10/11/2022
Oh! Weird that it's not stated obviously in the doc since it's atypical.
MMemw10/11/2022
imma see if all of this user agent thingy works
YYawnder10/11/2022
It's just not in the "Other Authentication" page.
MMemw10/11/2022
it was that
MMemw10/11/2022
damn
MMemw10/11/2022
i just
MMemw10/11/2022
requestClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(Client.Env["GITCREDS"])));
requestClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("JamieWorshipper", "1.0"));
requestClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
YYawnder10/11/2022
Good then!
MMemw10/11/2022
thanks a lot
MMemw10/11/2022
and sorry for the missunderstanding before
YYawnder10/11/2022
Don't worry. I have a short temper when I'm tired. I should go to bed 😉