Integration of native OS authentication services for Electron apps.
A request to receive authentication from a resource. The request must specify what URL scheme it expects the authentication callback to come from.
Example:
import { AuthRequest } from "electron-native-auth";
if (AuthRequest.isAvailable()) {
const req = new AuthRequest({
url,
callbackScheme,
windowHandle: myBrowserWindow.getNativeWindowHandle(),
});
const result = await req.start();
} else {
console.error("Native auth request unavailable :(");
}Indicates if this API is available on the current platform. This method is always available, even if the current platform is not supported.
- Parameters: None.
- Returns: A
boolean,trueif the rest of this class' methods are supported on the current platform.
Initializes, but does not start, an authentication request. A request can be started and later cancelled.
- Parameters:
- Options (
object):url(string): The URL to authenticate to.callbackScheme(string): The URL scheme (the part before://) that the callback is expected to have.windowHandle(Buffer): The native OS window handle for the window requesting authentication. Used when the OS prompts the user for authentication.headers({ [header: string]: string }, optional, macOS 14.4+): Headers and their values to add to HTTP requests sent during the authentication session.
- Options (
Begins the request to authenticate.
- Parameters: None.
- Returns: A
Promisethat resolves (withundefined) when the request has finished.
Cancels the authentication request.
- Parameters: None.
- Returns: Nothing.
- macOS: ✅
- Runtime: 10.15+
- Xcode SDK: 16+
- Uses ASWebAuthenticationSession
- Windows: ❌
- Linux: ❌