use cached JWT token and refresh on expiry

This commit is contained in:
Anish Mukherjee
2022-12-08 18:53:57 +05:30
parent 87f560f0ac
commit b2d0a6dfe9
4 changed files with 39 additions and 17 deletions

View File

@@ -27,7 +27,7 @@ func GetExtClient(networkName, clientID string) *models.ExtClient {
// GetExtClientConfig - fetch a wireguard config of an external client
func GetExtClientConfig(networkName, clientID string) string {
ctx := config.GetCurrentContext()
_, ctx := config.GetCurrentContext()
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/api/extclients/%s/%s/file", ctx.Endpoint, networkName, clientID), nil)
if err != nil {
log.Fatal(err)
@@ -35,7 +35,7 @@ func GetExtClientConfig(networkName, clientID string) string {
if ctx.MasterKey != "" {
req.Header.Set("Authorization", "Bearer "+ctx.MasterKey)
} else {
req.Header.Set("Authorization", "Bearer "+getAuthToken(ctx))
req.Header.Set("Authorization", "Bearer "+getAuthToken(ctx, true))
}
res, err := http.DefaultClient.Do(req)
if err != nil {