@yubion-dev-team/yubion-fido2-server-sdk-js
Version:
This project is an SDK to use YubiOn FIDO2 Server Service from Node.js.
225 lines (224 loc) • 12.9 kB
TypeScript
import { FssSdkConfigParameter } from "./fss-sdk-config";
import { UserDataRegisterParameter, UserDataUpdateParameter, UserDataWithCredentialCount } from "./schema/user-data";
import { CredentialData, CredentialDataUpdateParameter } from "./schema/credential-data";
import { Fido2FinishAuthenticateParameter, Fido2FinishRegisterParameter, Fido2StartAuthenticateParameter, Fido2StartRegisterParameter, SignalAllAcceptedCredentialsOptions, SignalCurrentUserDetailsOptions, SignalUnknownCredentialOptions } from "./schema";
export declare class YubiOnFssSdk {
private config;
private apiRequester;
/**
* Initializes a new instance of the YubiOnFssSdk class.
*
* @param {FssSdkConfigParameter} config - The configuration of the FIDO2 Server.
*/
constructor(config: FssSdkConfigParameter);
getRpId(): string;
/**
* Gets a user by its ID.
*
* @param {string} userId - The ID of the user to get.
* @param {boolean} [withDisabledUser=false] - Whether to include disabled users in the result.
* @param {boolean} [withDisabledCredential=false] - Whether to include disabled credentials in the result.
*
* @returns {Promise<{ user: UserDataWithCredentialCount, credentials: Array<CredentialData> }>}
* A promise that resolves with an object containing the user and credential data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
getUser(userId: string, withDisabledUser?: boolean, withDisabledCredential?: boolean): Promise<{
user: UserDataWithCredentialCount;
credentials: Array<CredentialData>;
signalCurrentUserDetailsOptions: SignalCurrentUserDetailsOptions;
}>;
/**
* Retrieves all users.
*
* @param {boolean} [withDisabledUser=false] - Whether to include disabled users in the result.
*
* @returns {Promise<{ users: Array<UserDataWithCredentialCount> }>}
* A promise that resolves with an object containing an array of user data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
getAllUsers(withDisabledUser?: boolean): Promise<{
users: Array<UserDataWithCredentialCount>;
}>;
/**
* Retrieves all users with the specified username.
*
* @param {string} userName - The username to search for.
* @param {boolean} [withDisabledUser=false] - Whether to include disabled users in the result.
*
* @returns {Promise<{ users: Array<UserDataWithCredentialCount> }>}
* A promise that resolves with an object containing an array of user data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
getUsersByUserName(userName: string, withDisabledUser?: boolean): Promise<{
users: Array<UserDataWithCredentialCount>;
}>;
/**
* Registers a new user.
*
* @param {UserDataRegisterParameter} user - The user data for registration.
*
* @returns {Promise<{ user: UserDataWithCredentialCount }>}
* A promise that resolves with an object containing the registered user data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
registerUser(user: UserDataRegisterParameter): Promise<{
user: UserDataWithCredentialCount;
}>;
/**
* Updates the specified user.
*
* @param {UserDataUpdateParameter} user - The user data for update.
* @param {boolean} [withUpdatedCheck=false] - Whether to check for the updated date.
*
* @returns {Promise<{ user: UserDataWithCredentialCount, signalCurrentUserDetailsOptions : SignalCurrentUserDetailsOptions }>}
* A promise that resolves with an object containing the updated user data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
updateUser(user: UserDataUpdateParameter, withUpdatedCheck?: boolean): Promise<{
user: UserDataWithCredentialCount;
signalCurrentUserDetailsOptions: SignalCurrentUserDetailsOptions;
}>;
/**
* Deletes a user by its ID.
*
* @param {string} userId - The ID of the user to delete.
*
* @returns {Promise<{ user: UserDataWithCredentialCount }>}
* A promise that resolves with an object containing the deleted user data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
deleteUser(userId: string): Promise<{
user: UserDataWithCredentialCount;
credentials: Array<CredentialData>;
signalAllAcceptedCredentialsOptions: SignalAllAcceptedCredentialsOptions;
}>;
/**
* Starts a credential registration process.
*
* @param {Fido2StartRegisterParameter} startRegisterParameter - The request parameter for starting a credential registration.
*
* @returns {Promise<{ creationOptions: PublicKeyCredentialCreationOptionsJSON, user: UserDataWithCredentialCount, session: string }>}
* A promise that resolves with an object containing the creation options for the credential registration and the user data, and a session string.
* The session string is used to verify the credential registration in the {@link verifyRegisterCredential} method and to finish the credential registration in the {@link finishRegisterCredential} method.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
startRegisterCredential(startRegisterParameter: Fido2StartRegisterParameter): Promise<{
session: string;
creationOptions: PublicKeyCredentialCreationOptionsJSON;
user: UserDataWithCredentialCount;
}>;
/**
* Verifies the credential registration parameters before the actual registration
* by analyzing the contents of the finishRegisterParameter. This method provides
* a clear and understandable format of the registration content for review.
* The return value should be checked by the RP (the program using the SDK) to
* determine if there are any issues. If no issues are found, the RP can proceed
* to call finishRegisterCredential. If there is no need to review the
* registration content, calling finishRegisterCredential directly is also acceptable.
*
* @param {Fido2FinishRegisterParameter} finishRegisterParameter - The parameters for finishing the credential registration.
* @param {string} session - The session string associated with the registration process.
*
* @returns {Promise<{ credential: CredentialData, user: UserDataWithCredentialCount }>}
* A promise that resolves with an object containing the credential data and user data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
verifyRegisterCredential(finishRegisterParameter: Fido2FinishRegisterParameter, session: string): Promise<{
credential: CredentialData;
user: UserDataWithCredentialCount;
}>;
/**
* Completes the credential registration process by verifying the credential
* registration information and saves the credential to the user account.
*
* @param {Fido2FinishRegisterParameter} finishRegisterParameter - The parameters for finishing the credential registration.
* @param {string} session - The session string associated with the registration process.
*
* @returns {Promise<{ credential: CredentialData, user: UserDataWithCredentialCount }>}
* A promise that resolves with an object containing the credential data and user data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
finishRegisterCredential(finishRegisterParameter: Fido2FinishRegisterParameter, session: string): Promise<{
credential: CredentialData;
user: UserDataWithCredentialCount;
}>;
/**
* Starts the authentication process with the specified user and parameters.
* If the user is not specified, the authentication is performed with discoverable credentials.
*
* @param {Fido2StartAuthenticateParameter} startAuthenticateParameter - The request parameter for starting an authentication.
*
* @returns {Promise<{ requestOptions: PublicKeyCredentialRequestOptionsJSON, user?: UserData, session: string }>}
* A promise that resolves with an object containing the request options for the authentication and the user data.
* If the user is not specified in the request parameter, the user data is null.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
* The session string is used to finish the authentication in the {@link finishAuthenticate} method.
*/
startAuthenticate(startAuthenticateParameter: Fido2StartAuthenticateParameter): Promise<{
session: string;
requestOptions: PublicKeyCredentialRequestOptionsJSON;
user?: UserDataWithCredentialCount;
}>;
/**
* Finishes the authentication process by verifying the authentication information.
*
* @param {Fido2FinishAuthenticateParameter} finishAuthenticateParameter - The parameters for finishing the authentication.
* @param {string} session - The session string associated with the authentication process.
*
* @returns {Promise<{ credential: CredentialData, user: UserDataWithCredentialCount }>}
* A promise that resolves with an object containing the credential data and user data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
finishAuthenticate(finishAuthenticateParameter: Fido2FinishAuthenticateParameter, session: string): Promise<{
credential: CredentialData;
user: UserDataWithCredentialCount;
signalAllAcceptedCredentialsOptions: SignalAllAcceptedCredentialsOptions;
signalCurrentUserDetailsOptions: SignalCurrentUserDetailsOptions;
}>;
/**
* Retrieves the credential with the specified ID belonging to the user with the specified ID.
*
* @param {string} userId - The ID of the user that the credential belongs to.
* @param {string} credentialId - The ID of the credential to retrieve.
* @param {boolean} [withDisabledUser=false] - Whether to include disabled users in the result.
* @param {boolean} [withDisabledCredential=false] - Whether to include disabled credentials in the result.
*
* @returns {Promise<{ user: UserDataWithCredentialCount, credential: CredentialData }>}
* A promise that resolves with an object containing the user data and the credential data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
getCredential(userId: string, credentialId: string, withDisabledUser?: boolean, withDisabledCredential?: boolean): Promise<{
user: UserDataWithCredentialCount;
credential: CredentialData;
}>;
/**
* Updates the specified credential.
*
* @param {CredentialDataUpdateParameter} credential - The credential data for update.
* @param {boolean} [withUpdatedCheck=false] - Whether to check for the updated date.
*
* @returns {Promise<{ user: UserDataWithCredentialCount, credential: CredentialData }>}
* A promise that resolves with an object containing the updated user data and credential data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
updateCredential(credential: CredentialDataUpdateParameter, withUpdatedCheck?: boolean): Promise<{
user: UserDataWithCredentialCount;
credential: CredentialData;
}>;
/**
* Deletes the credential with the specified ID belonging to the user with the specified ID.
*
* @param {string} userId - The ID of the user that the credential belongs to.
* @param {string} credentialId - The ID of the credential to delete.
*
* @returns {Promise<{ user: UserDataWithCredentialCount, credential: CredentialData, signalUnknownCredentialOptions : SignalUnknownCredentialOptions }>}
* A promise that resolves with an object containing the user data and the credential data.
* If the request fails due to an error in the external API, the promise is rejected with an `FssApiError`.
*/
deleteCredential(userId: string, credentialId: string): Promise<{
user: UserDataWithCredentialCount;
credential: CredentialData;
signalUnknownCredentialOptions: SignalUnknownCredentialOptions;
}>;
}