Added OAuth 2.0 authentication. Fixed #358
This commit is contained in:
@@ -341,13 +341,14 @@
|
|||||||
<span class="select-wrapper">
|
<span class="select-wrapper">
|
||||||
<select id="auth" v-model="auth">
|
<select id="auth" v-model="auth">
|
||||||
<option>None</option>
|
<option>None</option>
|
||||||
<option>Basic</option>
|
<option>Basic Auth</option>
|
||||||
<option>Bearer Token</option>
|
<option>Bearer Token</option>
|
||||||
|
<option>OAuth 2.0</option>
|
||||||
</select>
|
</select>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul v-if="auth === 'Basic'">
|
<ul v-if="auth === 'Basic Auth'">
|
||||||
<li>
|
<li>
|
||||||
<input
|
<input
|
||||||
placeholder="User"
|
placeholder="User"
|
||||||
@@ -385,7 +386,7 @@
|
|||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
</ul>
|
</ul>
|
||||||
<ul v-else-if="auth === 'Bearer Token'">
|
<ul v-if="auth === 'Bearer Token' || auth === 'OAuth 2.0'">
|
||||||
<li>
|
<li>
|
||||||
<input
|
<input
|
||||||
placeholder="Token"
|
placeholder="Token"
|
||||||
@@ -1357,9 +1358,10 @@ export default {
|
|||||||
if (this.requestType === "JavaScript XHR") {
|
if (this.requestType === "JavaScript XHR") {
|
||||||
const requestString = [];
|
const requestString = [];
|
||||||
requestString.push("const xhr = new XMLHttpRequest()");
|
requestString.push("const xhr = new XMLHttpRequest()");
|
||||||
const user = this.auth === "Basic" ? "'" + this.httpUser + "'" : null;
|
const user =
|
||||||
|
this.auth === "Basic Auth" ? "'" + this.httpUser + "'" : null;
|
||||||
const pswd =
|
const pswd =
|
||||||
this.auth === "Basic" ? "'" + this.httpPassword + "'" : null;
|
this.auth === "Basic Auth" ? "'" + this.httpPassword + "'" : null;
|
||||||
requestString.push(
|
requestString.push(
|
||||||
"xhr.open('" +
|
"xhr.open('" +
|
||||||
this.method +
|
this.method +
|
||||||
@@ -1373,7 +1375,7 @@ export default {
|
|||||||
pswd +
|
pswd +
|
||||||
")"
|
")"
|
||||||
);
|
);
|
||||||
if (this.auth === "Bearer Token") {
|
if (this.auth === "Bearer Token" || this.auth === "OAuth 2.0") {
|
||||||
requestString.push(
|
requestString.push(
|
||||||
"xhr.setRequestHeader('Authorization', 'Bearer " +
|
"xhr.setRequestHeader('Authorization', 'Bearer " +
|
||||||
this.bearerToken +
|
this.bearerToken +
|
||||||
@@ -1415,14 +1417,14 @@ export default {
|
|||||||
'fetch("' + this.url + this.pathName + this.queryString + '", {\n'
|
'fetch("' + this.url + this.pathName + this.queryString + '", {\n'
|
||||||
);
|
);
|
||||||
requestString.push(' method: "' + this.method + '",\n');
|
requestString.push(' method: "' + this.method + '",\n');
|
||||||
if (this.auth === "Basic") {
|
if (this.auth === "Basic Auth") {
|
||||||
const basic = this.httpUser + ":" + this.httpPassword;
|
const basic = this.httpUser + ":" + this.httpPassword;
|
||||||
headers.push(
|
headers.push(
|
||||||
' "Authorization": "Basic ' +
|
' "Authorization": "Basic ' +
|
||||||
window.btoa(unescape(encodeURIComponent(basic))) +
|
window.btoa(unescape(encodeURIComponent(basic))) +
|
||||||
'",\n'
|
'",\n'
|
||||||
);
|
);
|
||||||
} else if (this.auth === "Bearer Token") {
|
} else if (this.auth === "Bearer Token" || this.auth === "OAuth 2.0") {
|
||||||
headers.push(
|
headers.push(
|
||||||
' "Authorization": "Bearer ' + this.bearerToken + '",\n'
|
' "Authorization": "Bearer ' + this.bearerToken + '",\n'
|
||||||
);
|
);
|
||||||
@@ -1463,14 +1465,14 @@ export default {
|
|||||||
requestString.push(
|
requestString.push(
|
||||||
" '" + this.url + this.pathName + this.queryString + "' \\\n"
|
" '" + this.url + this.pathName + this.queryString + "' \\\n"
|
||||||
);
|
);
|
||||||
if (this.auth === "Basic") {
|
if (this.auth === "Basic Auth") {
|
||||||
const basic = this.httpUser + ":" + this.httpPassword;
|
const basic = this.httpUser + ":" + this.httpPassword;
|
||||||
requestString.push(
|
requestString.push(
|
||||||
" -H 'Authorization: Basic " +
|
" -H 'Authorization: Basic " +
|
||||||
window.btoa(unescape(encodeURIComponent(basic))) +
|
window.btoa(unescape(encodeURIComponent(basic))) +
|
||||||
"' \\\n"
|
"' \\\n"
|
||||||
);
|
);
|
||||||
} else if (this.auth === "Bearer Token") {
|
} else if (this.auth === "Bearer Token" || this.auth === "OAuth 2.0") {
|
||||||
requestString.push(
|
requestString.push(
|
||||||
" -H 'Authorization: Bearer " + this.bearerToken + "' \\\n"
|
" -H 'Authorization: Bearer " + this.bearerToken + "' \\\n"
|
||||||
);
|
);
|
||||||
@@ -1603,7 +1605,7 @@ export default {
|
|||||||
this.response.body = "Loading...";
|
this.response.body = "Loading...";
|
||||||
|
|
||||||
const auth =
|
const auth =
|
||||||
this.auth === "Basic"
|
this.auth === "Basic Auth"
|
||||||
? {
|
? {
|
||||||
username: this.httpUser,
|
username: this.httpUser,
|
||||||
password: this.httpPassword
|
password: this.httpPassword
|
||||||
@@ -1631,7 +1633,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the request uses a token for auth, we want to make sure it's sent here.
|
// If the request uses a token for auth, we want to make sure it's sent here.
|
||||||
if (this.auth === "Bearer Token")
|
if (this.auth === "Bearer Token" || this.auth === "OAuth 2.0")
|
||||||
headers["Authorization"] = `Bearer ${this.bearerToken}`;
|
headers["Authorization"] = `Bearer ${this.bearerToken}`;
|
||||||
|
|
||||||
headers = Object.assign(
|
headers = Object.assign(
|
||||||
|
|||||||
Reference in New Issue
Block a user