Skip to content

Commit 5aa25b4

Browse files
committed
Change make_credential() to return credential_id instead of true
This allows a caller to store the new credential_id together with e.g. a user_id for the user.
1 parent 390ac76 commit 5aa25b4

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

FUNCTIONS/make_credential.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CREATE OR REPLACE FUNCTION webauthn.make_credential(username text, challenge text, credential_raw_id text, credential_type text, attestation_object text, client_data_json text, relaying_party text)
2-
RETURNS boolean
2+
RETURNS bigint
33
LANGUAGE sql
44
AS $$
55
WITH
@@ -21,5 +21,5 @@ SELECT
2121
decode(attestation_object,'base64'),
2222
decode(client_data_json,'base64')
2323
FROM consume_challenge
24-
RETURNING TRUE
24+
RETURNING credential_id
2525
$$;

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ curl 'http://localhost/api/rpc/init_credential' \
114114
}
115115
```
116116

117-
<h3 id="make-credential"><code>webauthn.make_credential(username text, challenge base64, credential_raw_id base64, credential_type text, attestation_object base64, client_data_json base64, relaying_party text) RETURNS boolean</code></h3>
117+
<h3 id="make-credential"><code>webauthn.make_credential(username text, challenge base64, credential_raw_id base64, credential_type text, attestation_object base64, client_data_json base64, relaying_party text) RETURNS bigint</code></h3>
118118

119119
Stores the public key for the credential generated by the browser to the [webauthn.credentials](https://github.com/truthly/pg-webauthn/blob/master/TABLES/credentials.sql) table.
120120
The function also verifies there is an unconsumed matching `challenge` for the given `username`,
121121
which is consumed in the same transaction as the credential is stored.
122-
Returns `true` if successful.
122+
Returns `credential_id` of type `bigint` if successful.
123123

124124
Via `psql` prompt:
125125

@@ -144,7 +144,7 @@ curl 'http://localhost/api/rpc/make_credential' \
144144
```
145145

146146
```json
147-
true
147+
1
148148
```
149149

150150
<h3 id="sign-in">5.2. Sign-in functions</h3>

expected/invalid_base64.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ SELECT make_credential(
5454
);
5555
make_credential
5656
-----------------
57-
t
57+
1
5858
(1 row)
5959

6060
-- Replace random challenge with null to make test output predictable

expected/invalid_signature.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ SELECT make_credential(
5454
);
5555
make_credential
5656
-----------------
57-
t
57+
1
5858
(1 row)
5959

6060
-- Replace random challenge with null to make test output predictable

expected/valid_signature.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ SELECT make_credential(
5454
);
5555
make_credential
5656
-----------------
57-
t
57+
1
5858
(1 row)
5959

6060
-- Replace random challenge with null to make test output predictable

0 commit comments

Comments
 (0)