feat: proxy logout URL (#7)

pull/3756/head
Laurynas Gadliauskas 2021-06-03 09:43:28 +03:00 committed by GitHub
parent 9369e8ae31
commit 8fe3f85d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 12 deletions

View File

@ -1,8 +1,5 @@
SHELL := /bin/bash SHELL := /bin/bash
BASE_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 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 BIN = $(BASE_PATH)/bin
PATH := $(BIN):$(PATH) PATH := $(BIN):$(PATH)

View File

@ -35,6 +35,7 @@ func addConfigFlags(flags *pflag.FlagSet) {
flags.String("auth.method", string(auth.MethodJSONAuth), "authentication type") flags.String("auth.method", string(auth.MethodJSONAuth), "authentication type")
flags.String("auth.header", "", "HTTP header for auth.method=proxy") 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.host", "https://www.google.com", "use another host for ReCAPTCHA. recaptcha.net might be useful in China")
flags.String("recaptcha.key", "", "ReCaptcha site key") flags.String("recaptcha.key", "", "ReCaptcha site key")

View File

@ -33,6 +33,7 @@ override the options.`,
Signup: mustGetBool(flags, "signup"), Signup: mustGetBool(flags, "signup"),
Shell: convertCmdStrToCmdArray(mustGetString(flags, "shell")), Shell: convertCmdStrToCmdArray(mustGetString(flags, "shell")),
AuthMethod: authMethod, AuthMethod: authMethod,
AuthLogoutURL: mustGetString(flags, "auth.logoutUrl"),
Defaults: defaults, Defaults: defaults,
Branding: settings.Branding{ Branding: settings.Branding{
Name: mustGetString(flags, "branding.name"), Name: mustGetString(flags, "branding.name"),

View File

@ -49,6 +49,8 @@ you want to change. Other options will remain unchanged.`,
set.Signup = mustGetBool(flags, flag.Name) set.Signup = mustGetBool(flags, flag.Name)
case "auth.method": case "auth.method":
hasAuth = true hasAuth = true
case "auth.logoutUrl":
set.AuthLogoutURL = mustGetString(flags, flag.Name)
case "shell": case "shell":
set.Shell = convertCmdStrToCmdArray(mustGetString(flags, flag.Name)) set.Shell = convertCmdStrToCmdArray(mustGetString(flags, flag.Name))
case "branding.name": case "branding.name":

View File

@ -16,6 +16,6 @@ var versionCmd = &cobra.Command{
Use: "version", Use: "version",
Short: "Print the version number", Short: "Print the version number",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println("File Browser v" + version.Version + "/" + version.CommitSHA) fmt.Println("File Browser " + version.Version + "/" + version.CommitSHA)
}, },
} }

View File

@ -45,7 +45,10 @@
</router-link> </router-link>
<button <button
v-if="authMethod == 'json'" v-if="
authMethod == 'json' ||
(authMethod == 'proxy' && authLogoutURL != '')
"
@click="logout" @click="logout"
class="action" class="action"
id="logout" id="logout"
@ -108,6 +111,7 @@ import {
disableExternal, disableExternal,
noAuth, noAuth,
authMethod, authMethod,
authLogoutURL,
} from "@/utils/constants"; } from "@/utils/constants";
export default { export default {
@ -123,6 +127,7 @@ export default {
disableExternal: () => disableExternal, disableExternal: () => disableExternal,
noAuth: () => noAuth, noAuth: () => noAuth,
authMethod: () => authMethod, authMethod: () => authMethod,
authLogoutURL: () => authLogoutURL,
}, },
methods: { methods: {
help() { help() {

View File

@ -1,7 +1,7 @@
import store from "@/store"; import store from "@/store";
import router from "@/router"; import router from "@/router";
import { Base64 } from "js-base64"; import { Base64 } from "js-base64";
import { baseURL } from "@/utils/constants"; import { baseURL, authMethod, authLogoutURL } from "@/utils/constants";
export function parseToken(token) { export function parseToken(token) {
const parts = token.split("."); 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=/"; document.cookie = "auth=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/";
store.commit("setJWT", ""); store.commit("setJWT", "");
store.commit("setUser", null); store.commit("setUser", null);
localStorage.setItem("jwt", null); localStorage.setItem("jwt", null);
router.push({ path: "/login" }); router.push({ path: "/login" });
if (authMethod === "proxy" && authLogoutURL != "") {
try {
await fetch(`${authLogoutURL}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
} catch (e) {
this.$showError(e);
}
}
} }

View File

@ -9,6 +9,7 @@ const version = window.FileBrowser.Version;
const logoURL = `${staticURL}/img/logo.svg`; const logoURL = `${staticURL}/img/logo.svg`;
const noAuth = window.FileBrowser.NoAuth; const noAuth = window.FileBrowser.NoAuth;
const authMethod = window.FileBrowser.AuthMethod; const authMethod = window.FileBrowser.AuthMethod;
const authLogoutURL = window.FileBrowser.AuthLogoutURL;
const loginPage = window.FileBrowser.LoginPage; const loginPage = window.FileBrowser.LoginPage;
const theme = window.FileBrowser.Theme; const theme = window.FileBrowser.Theme;
const enableThumbs = window.FileBrowser.EnableThumbs; const enableThumbs = window.FileBrowser.EnableThumbs;
@ -26,6 +27,7 @@ export {
version, version,
noAuth, noAuth,
authMethod, authMethod,
authLogoutURL,
loginPage, loginPage,
theme, theme,
enableThumbs, enableThumbs,

View File

@ -35,6 +35,7 @@ func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys
"Signup": d.settings.Signup, "Signup": d.settings.Signup,
"NoAuth": d.settings.AuthMethod == auth.MethodNoAuth, "NoAuth": d.settings.AuthMethod == auth.MethodNoAuth,
"AuthMethod": d.settings.AuthMethod, "AuthMethod": d.settings.AuthMethod,
"AuthLogoutURL": d.settings.AuthLogoutURL,
"LoginPage": auther.LoginPage(), "LoginPage": auther.LoginPage(),
"CSS": false, "CSS": false,
"ReCaptcha": false, "ReCaptcha": false,

View File

@ -17,6 +17,7 @@ type Settings struct {
CreateUserDir bool `json:"createUserDir"` CreateUserDir bool `json:"createUserDir"`
Defaults UserDefaults `json:"defaults"` Defaults UserDefaults `json:"defaults"`
AuthMethod AuthMethod `json:"authMethod"` AuthMethod AuthMethod `json:"authMethod"`
AuthLogoutURL string `json:"authLogoutUrl"`
Branding Branding `json:"branding"` Branding Branding `json:"branding"`
Commands map[string][]string `json:"commands"` Commands map[string][]string `json:"commands"`
Shell []string `json:"shell"` Shell []string `json:"shell"`