Package com.mcawful
Class PanelPasskeyHandler
java.lang.Object
com.mcawful.PanelPasskeyHandler
Passkey registration, management and sign-in for
panel users.
Registration and management run over the authenticated panel websocket, so a user can
only ever touch their own passkeys. The exception is a setup link, made by someone who can
manage panel users or in the console, which adds a passkey over HTTP. Sign-in runs over HTTP
so the bot can set the session cookie of PanelSessionManager.
- Author:
- mcawful
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcreateSetupLink(String username) Creates a one-time link that lets a panel user add a passkey without signing in, replacing any earlier link of the user.static voiddeletePasskeys(String username) Removes all passkeys and setup links of a panel user and ends their sessions.static voidhandleHttp(ChannelHandlerContext ctx, FullHttpRequest req) Handles a request to/panel/login/passkey/, which the login page uses to sign in with a passkey or add one with a setup link.static voidhandleWs(ChannelHandlerContext ctx, PanelUser user, JSONObject request, JSONStringer response) Handles apasskeyquery on the panel websocketstatic booleanisMainLoginSession(HttpHeaders headers) Checks if a request carries a passkey session of the main login from botlogin.txt, which the Bot Setup and OAuth pages accept like its passwordstatic voidprintSetupLink(String token) Prints a setup link in the console.static voidprintStartupSetupLink(boolean newPassword) Prints a setup link for the main login from botlogin.txt while it has no passkey: at startup while panelpasswordless is on, since it has no other way to sign in to the panel, and next to a panel password the bot has just created, as the other way to sign instatic voidrenamePasskeys(String username, String newUsername) Moves all passkeys of a panel user to a new username and ends their sessions.
-
Method Details
-
handleWs
public static void handleWs(ChannelHandlerContext ctx, PanelUser user, JSONObject request, JSONStringer response) Handles apasskeyquery on the panel websocket- Parameters:
ctx- theChannelHandlerContextof the websocketuser- the authenticatedPanelUserrequest- thepasskeyobject of the query, which must have anactionresponse- theJSONStringerto write the single result value to
-
handleHttp
Handles a request to/panel/login/passkey/, which the login page uses to sign in with a passkey or add one with a setup link. These requests are not authenticated- Parameters:
ctx- theChannelHandlerContextof the requestreq- theFullHttpRequest
-
deletePasskeys
Removes all passkeys and setup links of a panel user and ends their sessions. Must be called when the user is deleted, so a later user with the same name does not inherit them, and when their password is reset, so nobody who had access keeps it- Parameters:
username- the user's name
-
renamePasskeys
Moves all passkeys of a panel user to a new username and ends their sessions. Must be called when the user is renamed. Passkeys and setup links that were left under the new name are removed first, so the user does not inherit them, and the user's setup links stop working- Parameters:
username- the user's current namenewUsername- the user's new name
-
createSetupLink
Creates a one-time link that lets a panel user add a passkey without signing in, replacing any earlier link of the user. The link works forSETUP_LINK_LIFETIME_MILLIS- Parameters:
username- the user's name- Returns:
- the token of the link, which goes after
/panel/login/#setup= - Throws:
IllegalArgumentException- if the user does not exist or can not use passkeys
-
printSetupLink
Prints a setup link in the console. The console does not know the address the panel is opened on, so the link uses localhost and the bot's port- Parameters:
token- the token of the link
-
printStartupSetupLink
public static void printStartupSetupLink(boolean newPassword) Prints a setup link for the main login from botlogin.txt while it has no passkey: at startup while panelpasswordless is on, since it has no other way to sign in to the panel, and next to a panel password the bot has just created, as the other way to sign in- Parameters:
newPassword-trueif the bot has just created the panel password
-
isMainLoginSession
Checks if a request carries a passkey session of the main login from botlogin.txt, which the Bot Setup and OAuth pages accept like its password- Parameters:
headers- the request headers- Returns:
trueif the session is valid and belongs to the main login
-