ntlm-webapi
Easily call a Windows authenticated web api service from Node
ChrisGeorge Framework
Inspired by the npm)
Installation (via$ npm install ntlm-webapi
Usage
Calling it from your app using a node style callback:
var Request = ; var request = url: "http://some.restful.api.org/you/want/to/call" username: 'username' password: 'password' domain: 'company_domain' ; request;
Calling it from your app using the promise based api:
var Request = ; var request = url: "http://some.restful.api.org/you/want/to/call" username: 'username' password: 'password' domain: 'company_domain' ; request ;
Authorizing the request first, and storing the token for subsequent calls
Alternatively, you can authorize the request when you start your web server so that subsequent calls will use the already authorized service call.
When authorizing first, you must pass the HTTP verb you plan to use when executing the service so ntlm-webapi knows which method to authenticate you against.
When authorizing first, you won't be logging in with each request. Keepaliveagent is used to keep the socket open. The following example shows how you can wire up a route after you've authorized the service so your app won't keep reauthorizing the service, but instead stay authorized with a cached token it received from the initial auth request.
var WebApi = ; var webapi = url: "http://some.restful.api.org/you/want/to/call" username: 'username' password: 'password' domain: 'company_domain' ; webapi /* token is not used here, but shown to illustrate it exists. It's cached in the `webapi` object */
Authorizing the request first and stringing promises
All methods return a promise so you can also string a group of promises like so
var WebApi = ; var webapi = url: "http://some.restful.api.org/you/want/to/call" username: 'username' password: 'password' domain: 'company_domain' ; webapi ;
Post Method
As of this version, only GET has been tested. POST is beta but has an API where you pass in the body as a json object. Multi-part is not yet handled.
var WebApi = ; var webapi = url: "http://some.restful.api.org/you/want/to/call" username: 'username' password: 'password' domain: 'company_domain' ; webapi ;
Configuration Object Options
Option | Description |
---|---|
url |
set to the full url address of the windows webapi you're calling. Be sure to include the protocol http:\\ or https:\\ in the address *note: only works with http right now |
username |
set this to your windows user account or a windows service account on the windows machine where the service resides |
password |
set to the windows account password for the account used above |
domain |
set to the windows domain where the service resides |
workstation |
(Optional) set to the windows workstation name if required by your network |
Other Notes
- The API will handle retry's if the connection closes because the connection has been idle. A retry will be sent to reauthorize the request. It will only try once, and then fail if unsuccessful on the second try.