@@ -89,6 +89,8 @@ This HTML example uses the Splunk Enterprise SDK for JavaScript to list all jobs
89
89
90
90
This example shows how to use the Splunk Enterprise SDK for JavaScript and Node.js to list all jobs:
91
91
92
+ ##### Login with username and password
93
+
92
94
``` javascript
93
95
var splunkjs = require (' splunk-sdk' );
94
96
@@ -107,6 +109,73 @@ This example shows how to use the Splunk Enterprise SDK for JavaScript and Node.
107
109
});
108
110
});
109
111
```
112
+ ##### Login with sessionKey
113
+
114
+ ``` shell
115
+ # Create a sessionKey
116
+ curl -k -u < username> :< password> < scheme> ://< host> :< port> /services/auth/login -d username=< username> -d password=< password>
117
+ ```
118
+
119
+ ``` javascript
120
+ var serviceWithSessionKey = new splunkjs.Service (
121
+ {
122
+ // Replace the host if you are accessing remote host
123
+ scheme: ' https' ,
124
+ host: ' localhost' ,
125
+ port: ' 8089' ,
126
+ sessionKey: SESSION_KEY , // Add your sessionKey here
127
+ version: ' 8' ,
128
+ });
129
+
130
+ serviceWithSessionKey .get (" search/jobs" , { count: 1 }, function (err , res ) {
131
+ if (err) {
132
+ console .log (err);
133
+ } else }
134
+ console .log (" Login successful with sessionKey" );
135
+ }
136
+ });
137
+ ```
138
+
139
+ ##### Login with token
140
+
141
+ ``` shell
142
+ # ### From shell ####
143
+ # Enable token authetication
144
+ curl -k -u < username> :< password> -X POST < scheme> ://< host> :< port> /services/admin/token-auth/tokens_auth -d disabled=false
145
+
146
+ # Create a token
147
+ curl -k -u < username> :< password> -X POST < scheme> ://< host> :< port> /services/authorization/tokens? output_mode=json --data name=< username> --data audience=Users --data-urlencode expires_on=+30d
148
+ ```
149
+
150
+ ``` shell
151
+ # ### From web ####
152
+ # Enable token authentication
153
+ Go to settings > Tokens and click on ' Enable Token Authentication'
154
+
155
+ # Create a token
156
+ 1. Go to settings > Token and click on ' New Token'
157
+ 2. Enter the relevant information
158
+ 3. Copy the created token and save it somewhere safe.
159
+ ```
160
+
161
+ ``` javascript
162
+ var serviceWithBearerToken = new splunkjs.Service (
163
+ {
164
+ // Replace the host if you are accessing remote host
165
+ scheme: ' https' ,
166
+ host: ' localhost' ,
167
+ port: ' 8089' ,
168
+ sessionKey: TOKEN , // Add your token here
169
+ version: ' 8' ,
170
+ });
171
+
172
+ serviceWithBearerToken .get (" search/jobs" , { count: 2 }, function (err , res ) {
173
+ if (err)
174
+ console .log (err);
175
+ else
176
+ console .log (" Login successful with bearer token" );
177
+ });
178
+ ```
110
179
111
180
## SDK examples
112
181
0 commit comments