send second id (client secret) as well with request
This commit is contained in:
parent
8f31a669d5
commit
d2d5968d02
2 changed files with 15 additions and 0 deletions
|
|
@ -11,6 +11,14 @@ import settings from './settings'
|
||||||
import xhr from './xhr'
|
import xhr from './xhr'
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
function initClientSecret() {
|
||||||
|
let SECRET = settings.getStr('SECRET', '')
|
||||||
|
if (!SECRET) {
|
||||||
|
SECRET = Util.uniqId()
|
||||||
|
settings.setStr('SECRET', SECRET)
|
||||||
|
}
|
||||||
|
return SECRET
|
||||||
|
}
|
||||||
function initClientId() {
|
function initClientId() {
|
||||||
let ID = settings.getStr('ID', '')
|
let ID = settings.getStr('ID', '')
|
||||||
if (!ID) {
|
if (!ID) {
|
||||||
|
|
@ -20,7 +28,9 @@ import xhr from './xhr'
|
||||||
return ID
|
return ID
|
||||||
}
|
}
|
||||||
const clientId = initClientId()
|
const clientId = initClientId()
|
||||||
|
const clientSecret = initClientSecret()
|
||||||
xhr.setClientId(clientId)
|
xhr.setClientId(clientId)
|
||||||
|
xhr.setClientSecret(clientSecret)
|
||||||
|
|
||||||
const res = await xhr.get(`/api/conf`, {})
|
const res = await xhr.get(`/api/conf`, {})
|
||||||
const conf = await res.json()
|
const conf = await res.json()
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ export interface Options {
|
||||||
}
|
}
|
||||||
|
|
||||||
let xhrClientId: string = ''
|
let xhrClientId: string = ''
|
||||||
|
let xhrClientSecret: string = ''
|
||||||
const request = async (
|
const request = async (
|
||||||
method: string,
|
method: string,
|
||||||
url: string,
|
url: string,
|
||||||
|
|
@ -25,6 +26,7 @@ const request = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
xhr.setRequestHeader('Client-Id', xhrClientId)
|
xhr.setRequestHeader('Client-Id', xhrClientId)
|
||||||
|
xhr.setRequestHeader('Client-Secret', xhrClientSecret)
|
||||||
|
|
||||||
xhr.addEventListener('load', function (ev: ProgressEvent<XMLHttpRequestEventTarget>
|
xhr.addEventListener('load', function (ev: ProgressEvent<XMLHttpRequestEventTarget>
|
||||||
) {
|
) {
|
||||||
|
|
@ -60,4 +62,7 @@ export default {
|
||||||
setClientId: (clientId: string): void => {
|
setClientId: (clientId: string): void => {
|
||||||
xhrClientId = clientId
|
xhrClientId = clientId
|
||||||
},
|
},
|
||||||
|
setClientSecret: (clientSecret: string): void => {
|
||||||
|
xhrClientSecret = clientSecret
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue