-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): per-device two factor method
This implements a per-device two factor method selection. The selection from the UI changes this value and the account wide selection has been moved to settings. Closes #1699 Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
- Loading branch information
1 parent
87747a5
commit b33dabb
Showing
15 changed files
with
309 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ func RequireElevated1FA(next RequestHandler) RequestHandler { | |
} | ||
|
||
ctx.ReplyForbidden() | ||
|
||
return | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const LocalStorageSecondFactorMethod = "second_factor_method"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Configuration } from "@models/Configuration"; | ||
import { ConfigurationPath } from "@services/Api"; | ||
import { Get } from "@services/Client"; | ||
import { Method2FA, toEnum } from "@services/UserInfo"; | ||
import { Method2FA, toSecondFactorMethod } from "@services/UserInfo"; | ||
|
||
interface ConfigurationPayload { | ||
available_methods: Method2FA[]; | ||
} | ||
|
||
export async function getConfiguration(): Promise<Configuration> { | ||
const config = await Get<ConfigurationPayload>(ConfigurationPath); | ||
return { ...config, available_methods: new Set(config.available_methods.map(toEnum)) }; | ||
return { ...config, available_methods: new Set(config.available_methods.map(toSecondFactorMethod)) }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { LocalStorageSecondFactorMethod } from "@constants/LocalStorage.ts"; | ||
import { SecondFactorMethod } from "@models/Methods.ts"; | ||
import { Method2FA, isMethod2FA, toMethod2FA, toSecondFactorMethod } from "@services/UserInfo.ts"; | ||
|
||
let hasLocalStorageSupport: null | boolean = null; | ||
const testKey = "authelia.test"; | ||
const testValue = "foo"; | ||
|
||
export function localStorageAvailable() { | ||
if (hasLocalStorageSupport !== null) return hasLocalStorageSupport; | ||
|
||
hasLocalStorageSupport = false; | ||
|
||
if (typeof window !== "undefined" && window.localStorage !== null) { | ||
hasLocalStorageSupport = true; | ||
|
||
try { | ||
window.localStorage.setItem(testKey, testValue); | ||
window.localStorage.removeItem(testKey); | ||
} catch (e) { | ||
hasLocalStorageSupport = false; | ||
} | ||
} | ||
|
||
return hasLocalStorageSupport; | ||
} | ||
|
||
export function removeLocalStorage(key: string) { | ||
if (!localStorageAvailable()) return false; | ||
|
||
window.localStorage.removeItem(key); | ||
|
||
return true; | ||
} | ||
|
||
export function getLocalStorage(key: string) { | ||
if (!localStorageAvailable()) return null; | ||
|
||
return window.localStorage.getItem(key); | ||
} | ||
|
||
export function setLocalStorage(key: string, value: string) { | ||
if (!localStorageAvailable()) return false; | ||
|
||
window.localStorage.setItem(key, value); | ||
|
||
return true; | ||
} | ||
|
||
export function setLocalStorageSecondFactorMethod(value: SecondFactorMethod): boolean { | ||
return setLocalStorage(LocalStorageSecondFactorMethod, toMethod2FA(value)); | ||
} | ||
|
||
export function getLocalStorageSecondFactorMethod(global: SecondFactorMethod): SecondFactorMethod { | ||
const method = getLocalStorage(LocalStorageSecondFactorMethod); | ||
|
||
if (method === null) return global; | ||
|
||
if (!isMethod2FA(method)) { | ||
return global; | ||
} | ||
|
||
const local: Method2FA = method as "webauthn" | "totp" | "mobile_push"; | ||
|
||
return toSecondFactorMethod(local); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.