SoftadminSnippet.BankId_Sign

Show allHide all
Type: Stored procedure

When called from a snippet procedure, initiates Mobile BankID signing and shows the ongoing status. Will trigger a BankID Completed call for the snippet when the process is completed.
Uses the same configuration as the BankID component.

Examples

With QR code
CREATE PROCEDURE Example.BankIdSnippet
	@IsFormSubmit bit = 0,

	@IsBankIdSign bit = 0,
	@PersonalNumber varchar(30) = NULL,
	@BankIdSignatureId int = NULL,
	@IsError bit = 0,
	@ErrorMessage varchar(MAX) = NULL
AS
BEGIN
	IF @IsFormSubmit = 1
	BEGIN
		EXEC SoftadminSnippet.BankId_Sign
			@UseQrCode = 1,
			@CultureCode = 'en-US',
			@TextToSign = N'Sign this!';

		RETURN;
	END;

	IF @IsBankIdSign = 1
	BEGIN
		SELECT CONCAT('Personal number: ', ISNULL(@PersonalNumber, 'N/A'), ', ') AS Plaintext;

		IF @IsError = 1
		BEGIN
			SELECT CONCAT('Error: ', @ErrorMessage) AS Plaintext;
			RETURN;
		END;

		SELECT 'Success!' AS Plaintext;

		-- Add code to log success and associate @BankIdSignatureId with relevant data here.

		RETURN;
	END;

	EXEC SoftadminSnippet.Form
		@FormHtml = N'<input type="submit" value="Show QR code">';

	SELECT '<div id="BankIdErrorMessage"></div>' AS Html;
END;
With user provided personal number
CREATE PROCEDURE Example.BankIdSnippet
	@IsFormSubmit bit = 0,

	@IsBankIdSign bit = 0,
	@PersonalNumber varchar(30) = NULL,
	@BankIdSignatureId int = NULL,
	@IsError bit = 0,
	@ErrorMessage varchar(MAX) = NULL
AS
BEGIN
	IF @IsFormSubmit = 1
	BEGIN
		DECLARE @EnteredPersonalNumber varchar(30);
		SELECT @EnteredPersonalNumber = [Value] FROM #FormValue WHERE [Name] = 'PersonalNumber';

		IF SoftadminSnippet.BankId_PersonalNumber_IsValid(@EnteredPersonalNumber) = 0
		BEGIN
			EXEC SoftadminSnippet.Element_SetContent
				@ElementId = N'BankIdErrorMessage',
				@Html = N'Invalid personal number.';

			RETURN;
		END;

		EXEC SoftadminSnippet.BankId_Sign
			@PersonalNumber = @EnteredPersonalNumber,
			@CultureCode = 'en-US',
			@TextToSign = N'Sign this!';

		RETURN;
	END;

	IF @IsBankIdSign = 1
	BEGIN
		SELECT CONCAT('Personal number: ', @PersonalNumber, ', ') AS Plaintext;

		IF @IsError = 1
		BEGIN
			SELECT CONCAT('Error: ', @ErrorMessage) AS Plaintext;
			RETURN;
		END;

		SELECT 'Success!' AS Plaintext;

		-- Add code to log success and associate @BankIdSignatureId with relevant data here.

		RETURN;
	END;

	EXEC SoftadminSnippet.Form
		@FormHtml = N'<label>Personal number: <input type="text" name="PersonalNumber"></label> <input type="submit">';

	SELECT '<div id="BankIdErrorMessage"></div>' AS Html;
END;

See also

Parameters

@CssClass optional varchar
CSS class name to use for the BankID status indicator.

Never target HTML elements internal to the status indicator from your CSS. The HTML may change between versions.
@CultureCode optional varchar
The language used for status messages. Defaults to 'sv-SE'.
Possible value Description
en-US English.
sv-SE Swedish.
@FormattedTextToSign optional varchar
Formatted text to sign, shown in the user's BankID app.

Supports e.g. headings, lists, and tables.
See https://www.bankid.com/assets/bankid/rp/guidelines-for-formatted-text-v1.1.pdf for formatting options.

Exactly one of @TextToSign and @FormattedTextToSign must be set.
@HiddenDataToSign optional varbinary
Additional data that will be signed but which is not shown to the user.

It might be tempting to include the entire document to sign (e.g. a PDF file) here, but it will require additional disk space. The data will be included in the signature (stored in SoftadminApi.BankIdSignature), which means that disk usage will increase proportionally to the size of the data.
@PersonalNumber mandatory varchar
Should consist of 12 digits. Hyphens are ignored.
Use SoftadminSnippet.BankId_PersonalNumber_IsValid to validate.
@TextToSign optional varchar
Text to sign, shown in the user's BankID app.

Exactly one of @TextToSign and @FormattedTextToSign must be set.
@UseQrCode optional bit
If set to 1, a QR code is shown for the user to scan with the BankID app.

@PersonalNumber is optional when using QR codes, but can still be provided to limit who is allowed to scan the code.