feat: proxy logout URL (#7)
parent
9369e8ae31
commit
8fe3f85d18
3
Makefile
3
Makefile
|
@ -1,8 +1,5 @@
|
|||
SHELL := /bin/bash
|
||||
BASE_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||
VERSION ?= $(shell git describe --tags --always --match=v* 2> /dev/null || \
|
||||
cat $(CURDIR)/.version 2> /dev/null || echo v0)
|
||||
VERSION_HASH = $(shell git rev-parse HEAD)
|
||||
|
||||
BIN = $(BASE_PATH)/bin
|
||||
PATH := $(BIN):$(PATH)
|
||||
|
|
|
@ -35,6 +35,7 @@ func addConfigFlags(flags *pflag.FlagSet) {
|
|||
|
||||
flags.String("auth.method", string(auth.MethodJSONAuth), "authentication type")
|
||||
flags.String("auth.header", "", "HTTP header for auth.method=proxy")
|
||||
flags.String("auth.logoutUrl", "", "Logout URL that should be called when auth.method=proxy")
|
||||
|
||||
flags.String("recaptcha.host", "https://www.google.com", "use another host for ReCAPTCHA. recaptcha.net might be useful in China")
|
||||
flags.String("recaptcha.key", "", "ReCaptcha site key")
|
||||
|
|
|
@ -29,11 +29,12 @@ override the options.`,
|
|||
authMethod, auther := getAuthentication(flags)
|
||||
|
||||
s := &settings.Settings{
|
||||
Key: generateKey(),
|
||||
Signup: mustGetBool(flags, "signup"),
|
||||
Shell: convertCmdStrToCmdArray(mustGetString(flags, "shell")),
|
||||
AuthMethod: authMethod,
|
||||
Defaults: defaults,
|
||||
Key: generateKey(),
|
||||
Signup: mustGetBool(flags, "signup"),
|
||||
Shell: convertCmdStrToCmdArray(mustGetString(flags, "shell")),
|
||||
AuthMethod: authMethod,
|
||||
AuthLogoutURL: mustGetString(flags, "auth.logoutUrl"),
|
||||
Defaults: defaults,
|
||||
Branding: settings.Branding{
|
||||
Name: mustGetString(flags, "branding.name"),
|
||||
DisableExternal: mustGetBool(flags, "branding.disableExternal"),
|
||||
|
|
|
@ -49,6 +49,8 @@ you want to change. Other options will remain unchanged.`,
|
|||
set.Signup = mustGetBool(flags, flag.Name)
|
||||
case "auth.method":
|
||||
hasAuth = true
|
||||
case "auth.logoutUrl":
|
||||
set.AuthLogoutURL = mustGetString(flags, flag.Name)
|
||||
case "shell":
|
||||
set.Shell = convertCmdStrToCmdArray(mustGetString(flags, flag.Name))
|
||||
case "branding.name":
|
||||
|
|
|
@ -16,6 +16,6 @@ var versionCmd = &cobra.Command{
|
|||
Use: "version",
|
||||
Short: "Print the version number",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("File Browser v" + version.Version + "/" + version.CommitSHA)
|
||||
fmt.Println("File Browser " + version.Version + "/" + version.CommitSHA)
|
||||
},
|
||||
}
|
||||
|
|
|
@ -45,7 +45,10 @@
|
|||
</router-link>
|
||||
|
||||
<button
|
||||
v-if="authMethod == 'json'"
|
||||
v-if="
|
||||
authMethod == 'json' ||
|
||||
(authMethod == 'proxy' && authLogoutURL != '')
|
||||
"
|
||||
@click="logout"
|
||||
class="action"
|
||||
id="logout"
|
||||
|
@ -108,6 +111,7 @@ import {
|
|||
disableExternal,
|
||||
noAuth,
|
||||
authMethod,
|
||||
authLogoutURL,
|
||||
} from "@/utils/constants";
|
||||
|
||||
export default {
|
||||
|
@ -123,6 +127,7 @@ export default {
|
|||
disableExternal: () => disableExternal,
|
||||
noAuth: () => noAuth,
|
||||
authMethod: () => authMethod,
|
||||
authLogoutURL: () => authLogoutURL,
|
||||
},
|
||||
methods: {
|
||||
help() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import store from "@/store";
|
||||
import router from "@/router";
|
||||
import { Base64 } from "js-base64";
|
||||
import { baseURL } from "@/utils/constants";
|
||||
import { baseURL, authMethod, authLogoutURL } from "@/utils/constants";
|
||||
|
||||
export function parseToken(token) {
|
||||
const parts = token.split(".");
|
||||
|
@ -82,11 +82,24 @@ export async function signup(username, password) {
|
|||
}
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
export async function logout() {
|
||||
document.cookie = "auth=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/";
|
||||
|
||||
store.commit("setJWT", "");
|
||||
store.commit("setUser", null);
|
||||
localStorage.setItem("jwt", null);
|
||||
router.push({ path: "/login" });
|
||||
|
||||
if (authMethod === "proxy" && authLogoutURL != "") {
|
||||
try {
|
||||
await fetch(`${authLogoutURL}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
this.$showError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ const version = window.FileBrowser.Version;
|
|||
const logoURL = `${staticURL}/img/logo.svg`;
|
||||
const noAuth = window.FileBrowser.NoAuth;
|
||||
const authMethod = window.FileBrowser.AuthMethod;
|
||||
const authLogoutURL = window.FileBrowser.AuthLogoutURL;
|
||||
const loginPage = window.FileBrowser.LoginPage;
|
||||
const theme = window.FileBrowser.Theme;
|
||||
const enableThumbs = window.FileBrowser.EnableThumbs;
|
||||
|
@ -26,6 +27,7 @@ export {
|
|||
version,
|
||||
noAuth,
|
||||
authMethod,
|
||||
authLogoutURL,
|
||||
loginPage,
|
||||
theme,
|
||||
enableThumbs,
|
||||
|
|
|
@ -35,6 +35,7 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys
|
|||
"Signup": d.settings.Signup,
|
||||
"NoAuth": d.settings.AuthMethod == auth.MethodNoAuth,
|
||||
"AuthMethod": d.settings.AuthMethod,
|
||||
"AuthLogoutURL": d.settings.AuthLogoutURL,
|
||||
"LoginPage": auther.LoginPage(),
|
||||
"CSS": false,
|
||||
"ReCaptcha": false,
|
||||
|
|
|
@ -17,6 +17,7 @@ type Settings struct {
|
|||
CreateUserDir bool `json:"createUserDir"`
|
||||
Defaults UserDefaults `json:"defaults"`
|
||||
AuthMethod AuthMethod `json:"authMethod"`
|
||||
AuthLogoutURL string `json:"authLogoutUrl"`
|
||||
Branding Branding `json:"branding"`
|
||||
Commands map[string][]string `json:"commands"`
|
||||
Shell []string `json:"shell"`
|
||||
|
|
Loading…
Reference in New Issue