Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

Added token based authentication type

rifqi3c4cb60cdafd
diff --git a/index.html b/index.html
index cd90bcd10..e852fe819 100644
--- a/index.html
+++ b/index.html
@@ -153,6 +153,7 @@
<select v-model="auth">
<option>None</option>
<option>Basic</option>
+ <option>Bearer Token</option>
</select>
</li>
</ul>
@@ -166,6 +167,12 @@
<input v-model="httpPassword" type="password">
</li>
</ul>
+ <ul v-if="auth === 'Bearer Token'">
+ <li>
+ <label for="bearer_token">Token</label>
+ <input v-model="bearerToken">
+ </li>
+ </ul>
</div>
</fieldset>
<fieldset class="parameters hidden">
diff --git a/script.js b/script.js
index a5360654c..110db3eff 100644
--- a/script.js
+++ b/script.js
@@ -18,6 +18,7 @@ const app = new Vue({
path: '/api',
httpUser: '',
httpPassword: '',
+ bearerToken: '',
params: [],
bodyParams: [],
contentType: 'application/json',
@@ -133,6 +134,9 @@ const app = new Vue({
const user = this.auth === 'Basic' ? this.httpUser : null
const pswd = this.auth === 'Basic' ? this.httpPassword : null
xhr.open(this.method, this.url + this.path + this.queryString, true, user, pswd)
+ if (this.auth === 'Bearer Token') {
+ xhr.setRequestHeader('Authorization', 'Bearer ' + this.bearerToken);
+ }
if (this.method === 'POST' || this.method === 'PUT') {
const requestBody = this.rawRequestBody
xhr.setRequestHeader('Content-Length', requestBody.length)