Asana API Key Basic authentication 401 -
i getting 401 response asana request.
var url = "https://app.asana.com/api/1.0/users/me"; byte[] encodedbyte = system.text.asciiencoding.ascii.getbytes(apikey); apikey = convert.tobase64string(encodedbyte); webrequest wrgeturl; wrgeturl = webrequest.create(url); wrgeturl.headers.add("authorization: basic " + apikey); string result; using (streamreader reader = new streamreader(wrgeturl.getresponse().getresponsestream())) { result = reader.readtoend(); } return result;
the way http basic auth works, encode username and password base64, separated colon. in asana api key username , there no password.
from docs @ https://asana.com/developers/documentation/getting-started/authentication#sts=api%20keys :
note: utilities , libraries allow specify username , password handle proper encoding of header you. however, if need set authorization header manually, header value constructed adding colon (:) api key, base64-encoding string. can read more on basic authentication if need further details.
so, should do:
byte[] encodedbyte = system.text.asciiencoding.ascii.getbytes(apikey + ":")
Comments
Post a Comment