@criipto/verify-react
Version:
Verify SDK for React Single Page Applications
267 lines (266 loc) • 9 kB
TypeScript
import React from "react";
import * as _criipto_auth_js0 from "@criipto/auth-js";
import CriiptoAuth, { OAuth2Error, OAuth2Error as OAuth2Error$1, PKCEPublicPart, Prompt, ResponseType } from "@criipto/auth-js";
import * as react_jsx_runtime0 from "react/jsx-runtime";
//#region src/context.d.ts
type ResultSource = 'QRCode' | 'SEBankIDQrCode' | 'SEBankIDSameDeviceButton' | 'redirect' | 'popup';
type Result = {
id_token: string;
state?: string;
source?: ResultSource;
} | {
code: string;
state?: string;
source?: ResultSource;
} | OAuth2Error$1 | Error;
declare const actions: readonly ["confirm", "accept", "approve", "sign", "login"];
type Action = (typeof actions)[number];
type Claims = {
iss: string;
aud: string;
identityscheme: string;
authenticationtype: string;
sub: string;
iat: number;
exp: number;
[key: string]: string | number;
};
//#endregion
//#region src/provider.d.ts
interface CriiptoVerifyProviderOptions {
domain: string;
clientID: string;
/**
* @deprecated Development use only
*/
protocol?: 'https' | 'http';
redirectUri?: string;
children: React.ReactNode;
pkce?: PKCEPublicPart;
state?: string;
nonce?: string;
prompt?: Prompt;
scope?: string;
uiLocales?: string;
loginHint?: string;
/**
* Enables storage and automatic fetch of tokens
* by utilizing browser storage and SSO silent logins.
* Make sure "SSO for OAuth2" is enabled on your Criipto Domain.
* Only works for `response: 'token'` (default)
*/
sessionStore?: Storage;
/**
* Will ammend the login_hint parameter with `action:{action}` which will adjust texsts in certain flows.
* Default: 'login'
*/
action?: Action;
/**
* Will ammend the login_hint parameter with `message:{base64(message)}` which will set a login/aprove message where available (Danish MitID).
*/
message?: string;
/**
* Note: In most cases modifying this setting **is not needed**. Defaults will work with almost all React SPA cases.
* By default @criipto/verify-react will do PKCE on your behalf and return a jwt token.
* However if you wish you can disable this and get the raw `code` response by setting `response` to 'code'.
*/
response?: 'token' | 'code';
completionStrategy?: 'client' | 'openidprovider';
/**
* @deprecated Criipto internal use
*/
criiptoSdk?: null | string;
/**
* @deprecated Criipto internal use
*/
responseType?: ResponseType | 'code id_token';
/**
* @deprecated Criipto internal use
*/
responseMode?: 'query' | 'form_post' | 'fragment' | 'json' | 'post_message';
}
declare const CriiptoVerifyProvider: (props: CriiptoVerifyProviderOptions) => React.ReactElement;
//#endregion
//#region src/i18n/index.d.ts
type Language = 'en' | 'da' | 'sv' | 'nb' | 'fi' | 'de' | 'nl';
//#endregion
//#region src/components/AuthMethodButton/Logo.d.ts
interface AuthMethodButtonLogoProps {
acrValue: string;
/**
* base64 image string, e.x. data:image/png;base64,
* or a ReactElement
*/
logo?: React.ReactElement | string;
}
//#endregion
//#region src/components/AuthMethodButton.d.ts
type PopupParams = {
acrValue: string;
onHide: () => void;
};
type PopupOption = boolean | ((options: PopupParams) => boolean | React.ReactElement);
interface AuthMethodButtonComponentProps {
acrValue: string;
href?: string;
onClick?: React.MouseEventHandler;
children?: React.ReactNode;
'data-testid'?: string;
className?: string;
/**
* base64 image string, e.x. data:image/png;base64,
* or a ReactElement
*/
logo?: AuthMethodButtonLogoProps['logo'];
/**
* Impacts the button text rendered if no text is provided via props.children
*/
language?: Language;
/**
* Impacts the button text rendered if no text is provided via props.children
*/
action?: Action;
disabled?: boolean;
loading?: boolean;
}
/**
* Display only components, does no state management and triggers no login flows on it's own
*/
declare function AuthMethodButtonComponent(props: AuthMethodButtonComponentProps): react_jsx_runtime0.JSX.Element;
type AuthMethodButtonContainerProps = AuthMethodButtonComponentProps & {
redirectUri?: string;
popup?: PopupOption;
/**
* Will ammend the login_hint parameter with `message:{base64(message)}` which will set a login/aprove message where available (Danish MitID).
*/
message?: string;
userAgent?: string;
};
declare function AuthMethodButtonContainer(props: AuthMethodButtonContainerProps): react_jsx_runtime0.JSX.Element;
//#endregion
//#region src/components/AuthMethodSelector.d.ts
interface AuthMethodSelectorProps {
acrValues?: string[];
language?: Language;
onSelect?: (acrValue: string) => void;
redirectUri?: string;
popup?: AuthMethodButtonContainerProps['popup'];
userAgent?: string;
}
declare function AuthMethodSelector(props: AuthMethodSelectorProps): react_jsx_runtime0.JSX.Element;
type SwedenProps = Omit<AuthMethodSelectorProps, 'acrValues'> & {
acrValues: string[];
};
declare function Sweden(props: SwedenProps): react_jsx_runtime0.JSX.Element;
//#endregion
//#region src/components/AuthButtonGroup.d.ts
declare function AuthButtonGroup(props: {
children: React.ReactNode;
}): react_jsx_runtime0.JSX.Element;
//#endregion
//#region src/components/QRCode.d.ts
declare const QRCode: React.FC<{
margin?: number;
className?: string;
acrValues?: string[];
children: (props: {
qrElement: React.ReactElement;
/**
* Will be true once the QR code has been scanned
*/
isAcknowledged: boolean;
/**
* Will be true if the user cancels the login on his mobile device
*/
isCancelled: boolean;
/**
* Whether or not QR codes are enabled for this Criipto Applicaiton
*/
isEnabled: boolean | undefined;
error: OAuth2Error$1 | Error | null;
retry: () => void;
/**
* A method for triggering a full screen redirect to authentication (useful if user is on mobile device already)
*/
redirect: () => Promise<void>;
}) => React.ReactElement;
}>;
//#endregion
//#region src/components/SEBankIDQRCode.d.ts
interface Props {
redirectUri?: string;
qrMargin?: number;
/**
* Impacts the help text
*/
language?: Language;
children?: (props: {
qrElement: React.ReactElement;
/**
* Can be rendered instead of `qrElement` if you only wish to render the qr code with no additional content.
* Combine with `qrMargin`.
*/
imageElement: React.ReactElement;
/**
* Will be true once the user has completed login in the app and the rest of the login flow is being processed
*/
isCompleting: boolean;
/**
* The user has clicked on the qr image element to trigger fullscreen view per https://developers.bankid.com/getting-started/qr-code#accessibility
*/
fullscreen: boolean;
error: OAuth2Error$1 | Error | null;
retry: () => void;
}) => React.ReactElement;
/** Render fallback element while loading */
fallback?: React.ReactElement;
}
declare function SEBankIDQrCode(props: Props): react_jsx_runtime0.JSX.Element;
declare namespace SEBankIDQrCode {
var acr_values: string;
}
//#endregion
//#region src/use-criipto-verify.d.ts
declare function useCriiptoVerify(): {
result: Result | null;
/**
* The claims of the decoded id_token (if available)
*/
claims: Claims | null;
/**
* Set when the provider failed to fetch configuration (e.g. invalid `domain`/`clientID`,
* or CORS), or when an authentication attempt failed (e.g. user cancellation, OAuth2 errors
* from the IdP). Always render this in your UI — failures are otherwise silent.
*
* `OAuth2Error` for IdP-returned errors, `Error` for everything else.
*/
error: Error | null;
loginWithRedirect: (params?: _criipto_auth_js0.RedirectAuthorizeParams) => Promise<void>;
loginWithPopup: (params?: _criipto_auth_js0.PopupAuthorizeParams) => Promise<void>;
acrValues: string[] | undefined;
/**
* Will be true when performing token exchange after redirect or during an initial SSO check
*/
isLoading: boolean;
/**
* Will be true until the first set of useEffect hooks have been called
*/
isInitializing: boolean;
/**
* Check if there is an existing SSO session.
*/
checkSession: () => Promise<void>;
/**
* Clear local session store and logout of any existing SSO session
*/
logout: (params?: {
redirectUri?: string;
state?: string;
}) => Promise<void>;
};
//#endregion
//#region src/utils.d.ts
declare function filterAcrValues(input: string[]): string[];
//#endregion
export { type Action, AuthMethodButtonContainer as AuthButton, AuthMethodButtonContainer as AuthMethodButton, AuthMethodButtonComponent as AuthButtonComponent, AuthButtonGroup, AuthMethodSelector, Sweden as AuthMethodSelectorSweden, CriiptoVerifyProvider, type Language, OAuth2Error, QRCode, type Result, SEBankIDQrCode as SEBankIDQRCode, actions, filterAcrValues, useCriiptoVerify };
//# sourceMappingURL=index.d.ts.map