vb.net - How do I add just a username within an authentication header in stripe-payments? -
i'm trying simple post request work create customer via stripe.js api.
https://stripe.com/docs/api/java#authentication
i'm doing in vb.net , don't want use stripe.net library.
i keep getting authorization failed. have pass username in header, or in case username test api key.
here's chunk of code:
dim aspostrequest httpwebrequest = webrequest.create(string.format(apiendpoint)) dim as_bytearray byte() = encoding.utf8.getbytes(stripeccw.tostring) aspostrequest.method = "post" aspostrequest.contenttype = "application/json" 'aspostrequest.headers("authorization") = "basic" + apikey 'aspostrequest.credentials("bearer", apikey) 'aspostrequest.headers.add("authorization") = apikey 'aspostrequest.credentials("username") = apikey 'aspostrequest.credentials = new networkcredential(apikey, "") aspostrequest.contentlength = as_bytearray.length dim as_datastream stream = aspostrequest.getrequeststream() as_datastream.write(as_bytearray, 0, as_bytearray.length) as_datastream.close()
where i've commented out... different ways i've tried. know stupid attempts, getting frustrated. know fact api key correct. can verify navigating https://api.stripe.com/v1/customers , entering in username only.
hoping can spot simple :)
thank you!
if in shoes, first thing i'd take @ how stripe.net it. if don't want use library yourself, doesn't mean can't use source code reference.
from requestor.cs:
internal static webrequest getwebrequest(string url, string method, string apikey = null, bool usebearer = false) { apikey = apikey ?? stripeconfiguration.getapikey(); var request = (httpwebrequest)webrequest.create(url); request.method = method; if(!usebearer) request.headers.add("authorization", getauthorizationheadervalue(apikey)); else request.headers.add("authorization", getauthorizationheadervaluebearer(apikey)); request.headers.add("stripe-version", stripeconfiguration.apiversion); request.contenttype = "application/x-www-form-urlencoded"; request.useragent = "stripe.net (https://github.com/jaymedavis/stripe.net)"; return request; } private static string getauthorizationheadervalue(string apikey) { var token = convert.tobase64string(encoding.utf8.getbytes(string.format("{0}:", apikey))); return string.format("basic {0}", token); } private static string getauthorizationheadervaluebearer(string apikey) { return string.format("bearer {0}", apikey); }
so seems there 2 ways it. can either use "bearer" format, is:
aspostrequest.headers.add("authorization", "bearer " & apikey)
or can use "basic" format is:
aspostrequest.headers.add("authorization", _ "basic " & convert.tobase64string(encoding.utf8.getbytes(apikey & ":")))
Comments
Post a Comment