Added token based authentication type

User can choose Bearer Token authentication type to access apis protected with access/id token.
This commit is contained in:
rifqi
2019-08-23 15:34:40 +09:00
parent 8164e9712b
commit 3c4cb60cda
2 changed files with 11 additions and 0 deletions

View File

@@ -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)