Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: invalid byte sequence for encoding postgres #25

Open
ibrunotome opened this issue Nov 8, 2021 · 2 comments
Open

bug: invalid byte sequence for encoding postgres #25

ibrunotome opened this issue Nov 8, 2021 · 2 comments

Comments

@ibrunotome
Copy link

My only change is the use of uuid instead of bigint in the migration:

Schema::create('webauthn_credentials', function (Blueprint $table) {
    $table->id();
    $table->foreignIdFor(User::class)->constrained()->cascadeOnDelete();
    $table->binary('credId');
    $table->binary('key');
    $table->timestamps();
});

Right after confirm with TouchID:

[2021-11-08 11:57:44] production.DEBUG: No attestation is asked.
[2021-11-08 11:57:44] production.DEBUG: The Attestation Statement is anonymous.
[2021-11-08 11:57:44] production.ERROR: An error occurred {"exception":"[object] (Illuminate\Database\QueryException(code: 22021): SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0x85 (SQL: select * from "webauthn_credentials" where "credId" = �-�?\u0001��Kzʎw��cg��k� limit 1) at /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:703)
[stacktrace]
#0 /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(663): Illuminate\Database\Connection->runQueryCallback()
#1 /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(367): Illuminate\Database\Connection->run()
#2 /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2350): Illuminate\Database\Connection->select()
#3 /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2338): Illuminate\Database\Query\Builder->runSelect()
#4 /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2872): Illuminate\Database\Query\Builder->Illuminate\Database\Query\{closure}()
#5 /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2339): Illuminate\Database\Query\Builder->onceWithColumns()
#6 /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(615): Illuminate\Database\Query\Builder->get()
#7 /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(599): Illuminate\Database\Eloquent\Builder->getModels()
#8 /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(259): Illuminate\Database\Eloquent\Builder->get()
#9 /data/wwwroot/app/vendor/m1guelpf/laravel-fastlogin/src/Utils/CredentialSource.php(16): Illuminate\Database\Eloquent\Builder->first()
#10 /data/wwwroot/app/vendor/web-auth/webauthn-lib/src/AuthenticatorAttestationResponseValidator.php(204): M1guelpf\FastLogin\Utils\CredentialSource->findOneByCredentialId()
#11 /data/wwwroot/app/vendor/m1guelpf/laravel-fastlogin/src/Http/Controllers/FastLoginController.php(58): Webauthn\AuthenticatorAttestationResponseValidator->check()
#12 /data/wwwroot/app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(48): M1guelpf\FastLogin\Http\Controllers\FastLoginController->create()

@ibrunotome
Copy link
Author

ibrunotome commented Nov 8, 2021

Can be solved with:

$request->user()->webauthnCredentials()->create([
     'credId' => $credId = pg_escape_string(utf8_encode($response->getPublicKeyCredentialId())),
     'key'    => pg_escape_string(utf8_encode($response->getCredentialPublicKey())),
]);

on https://github.com/m1guelpf/laravel-fastlogin/blob/main/src/Http/Controllers/FastLoginController.php#L63

And

$credential = WebAuthnCredential::where('credId', pg_escape_string(utf8_encode($publicKeyCredentialId)))->first();

on https://github.com/m1guelpf/laravel-fastlogin/blob/main/src/Utils/CredentialSource.php#L16

Then the record will be saved on database, but after that on iPhone when I submit to fast login, nothing happens, with no backend errors and I don't know how to get mobile console errors.

@hassanelhallaq
Copy link

hassanelhallaq commented Mar 28, 2022

Can be solved with:

$request->user()->webauthnCredentials()->create([
     'credId' => $credId = pg_escape_string(utf8_encode($response->getPublicKeyCredentialId())),
     'key'    => pg_escape_string(utf8_encode($response->getCredentialPublicKey())),
]);

on https://github.com/m1guelpf/laravel-fastlogin/blob/main/src/Http/Controllers/FastLoginController.php#L63

And

$credential = WebAuthnCredential::where('credId', pg_escape_string(utf8_encode($publicKeyCredentialId)))->first();

on https://github.com/m1guelpf/laravel-fastlogin/blob/main/src/Utils/CredentialSource.php#L16

Then the record will be saved on database, but after that on iPhone when I submit to fast login, nothing happens, with no backend errors and I don't know how to get mobile console errors.

hi , how are you did you use the packge with api and passport , and can you help me to integrate with it :)

GitHub
Allow your users to login with FaceID/TouchID. Contribute to m1guelpf/laravel-fastlogin development by creating an account on GitHub.
GitHub
Allow your users to login with FaceID/TouchID. Contribute to m1guelpf/laravel-fastlogin development by creating an account on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants