node.js - NodeJS Native basic authentication -


is there node-native way parse basic authentication?

steps be:

  • find authentication header
  • parse encoded value
  • tokenize on colon , return user/pass
  • perhaps friendly error handling/messaging on fail

not looking connect/express framework solutions.

i realize pretty trivial hand nice have standard way achieve without re-inventing wheel.

so http auth has confusing thing. when have url credentials https://user:password@example.com', parse fine withurl.parse`:

 url.parse('https://user:password@example.com') { protocol: 'https:',   slashes: true,   auth: 'user:password',   host: 'example.com',   port: null,   hostname: 'example.com',   hash: null,   search: null,   query: null,   pathname: '/',   path: '/',   href: 'https://user:password@example.com/' } 

note it's url.parse(theurl).auth not url.parse(theurl).query.auth have.

however, url itself, string. if tell http library request url, credentials translated http request header, rest of url host, path, port, etc each gets converted details of request , within http request header , body full url found because it's spread out across both tcp , http layers.

which long way of saying need in request headers: req.headers.authorization. url.parse looks @ simple url string , have on server actual http.clientrequest instance.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -