mirror of
https://github.com/1f349/lavender.git
synced 2024-12-22 07:34:06 +00:00
Rewrite test client token refreshing
This commit is contained in:
parent
e1825ce1e8
commit
602a964a0b
1
go.mod
1
go.mod
@ -14,7 +14,6 @@ require (
|
|||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/julienschmidt/httprouter v1.3.0
|
github.com/julienschmidt/httprouter v1.3.0
|
||||||
github.com/mattn/go-sqlite3 v1.14.22
|
github.com/mattn/go-sqlite3 v1.14.22
|
||||||
github.com/rs/cors v1.10.1
|
|
||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.8.4
|
||||||
golang.org/x/oauth2 v0.16.0
|
golang.org/x/oauth2 v0.16.0
|
||||||
)
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -100,8 +100,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||||
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
|
|
||||||
github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
|
|
||||||
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
|
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
|
||||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<script>
|
<script>
|
||||||
const ssoService = "http://localhost:9090";
|
const ssoService = "http://localhost:9090";
|
||||||
|
|
||||||
POP2.init(ssoService + "/authorize", "f4cdb93d-fe28-427b-b037-f03f44c86a16", "openid profile", 500, 600);
|
POP2.init(ssoService + "/authorize", "bc36b32c-83cb-404e-8736-cb207f30afe3", "openid profile", 500, 600);
|
||||||
|
|
||||||
function updateTokenInfo(data) {
|
function updateTokenInfo(data) {
|
||||||
document.getElementById("someTextArea").textContent = JSON.stringify(data, null, 2);
|
document.getElementById("someTextArea").textContent = JSON.stringify(data, null, 2);
|
||||||
|
@ -135,24 +135,40 @@
|
|||||||
clientRequest: function (resource, options, refresh = false) {
|
clientRequest: function (resource, options, refresh = false) {
|
||||||
const sendRequest = function () {
|
const sendRequest = function () {
|
||||||
options.credentials = 'include';
|
options.credentials = 'include';
|
||||||
if (options.headers) {
|
if (!options.headers) options.headers = {};
|
||||||
options.headers['Authorization'] = 'Bearer ' + access_token;
|
options.headers['Authorization'] = 'Bearer ' + access_token;
|
||||||
}
|
|
||||||
return fetch(resource, options);
|
|
||||||
};
|
|
||||||
if (!refresh) return sendRequest();
|
|
||||||
else {
|
|
||||||
return new Promise(function (res, rej) {
|
return new Promise(function (res, rej) {
|
||||||
sendRequest().then(function (x) {
|
fetch(resource, options).then(function (x) {
|
||||||
res(x)
|
if (x.statusCode >= 200 && x.statusCode < 300) res(x);
|
||||||
}).catch(function () {
|
else rej(x);
|
||||||
w.POP2.getToken(function () {
|
}).catch(function (x) {
|
||||||
|
rej(x);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const resendRequest = function() {
|
||||||
|
return new Promise(function (res, rej) {
|
||||||
|
w.POP2.getToken(function() {
|
||||||
sendRequest().then(function (x) {
|
sendRequest().then(function (x) {
|
||||||
res(x);
|
res(x);
|
||||||
}).catch(function (x) {
|
}).catch(function (x) {
|
||||||
rej(x);
|
rej(x);
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!refresh) return sendRequest();
|
||||||
|
else {
|
||||||
|
return new Promise(function (res, rej) {
|
||||||
|
sendRequest().then(function (x) {
|
||||||
|
res(x);
|
||||||
|
}).catch(function () {
|
||||||
|
resendRequest().then(function (x) {
|
||||||
|
res(x);
|
||||||
|
}).catch(function (x) {
|
||||||
|
rej(x);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user