<@U04UQ68083H> example for implementing passkeys i...
# ory-copilot
b
@chilly-king-10285 example for implementing passkeys in flutter web using nativeRegistrationFlow
c
A message from kapa.ai
I'm sorry, but the provided knowledge sources do not contain an example of implementing passkeys in Flutter web using nativeRegistrationFlow. The available information is about creating a registration flow, getting a registration flow, submitting a registration flow, and a Flutter code example for implementing a Sign in with Google button using the Ory SDK. For more detailed information, you may want to refer to the official Ory documentation or the specific guide for the feature you're interested in.
b
yes that one creating a registration flow
@chilly-king-10285 that one creating a registration flow
c
A message from kapa.ai
Creating a registration flow in Ory involves several steps. Here's a basic example of how you can do this in TypeScript:
Copy code
typescript import {     Configuration,     FrontendApi,     RegistrationFlow,     UiNode,     UiNodeInputAttributes,   } from "@ory/client"   import {     filterNodesByGroups,     isUiNodeInputAttributes,   } from "@ory/integrations/ui"   import { useEffect, useState } from "react"   import { useSearchParams } from "react-router-dom"      const frontend = new FrontendApi(     new Configuration({       basePath: "<http://localhost:4000>", // Use your local Ory Tunnel URL       baseOptions: {         withCredentials: true, // we need to include cookies       },     }),   )      export const Registration = () => {     const [flow, setFlow] = useState<RegistrationFlow>()     const [searchParams] = useSearchParams()        useEffect(() => {       // we can redirect the user back to the page they were on before login       const returnTo = searchParams.get("return_to")          frontend         .createBrowserRegistrationFlow({           returnTo: returnTo || "/", // redirect to the root path after login         })         .then(({ data: flow }) => {           // set the flow data           setFlow(flow)         })         .catch((err) => {           // Couldn't create login flow           // handle the error         })     }, [])     // ...   }
This code creates a new registration flow when the
Registration
component is mounted. The
createBrowserRegistrationFlow
method is used to create the flow. The
returnTo
parameter is used to specify where to redirect the user after they have logged in. If the flow is successfully created, it is stored in the
flow
state variable. If there is an error creating the flow, it is handled in the
catch
block. Please note that this is a basic example and you might need to adjust it according to your needs. For more detailed information, you can refer to the [Ory documentation](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#create-registration-flow).
b
@chilly-king-10285 but I need it in Flutter
c
A message from kapa.ai
I'm sorry for the confusion, but the provided knowledge sources do not contain an example of creating a registration flow in Flutter. The available Flutter example is for implementing a Sign in with Google button using the Ory SDK. Here's the available Flutter code example:
Copy code
dart import 'package:flutter/material.dart';   import 'package:google_sign_in/google_sign_in.dart';   import 'package:one_of/one_of.dart';   import 'package:ory_client/ory_client.dart';      class SignInWithGoogleButton extends StatelessWidget {     final String flowId;     final OryClient ory;        final GoogleSignIn _googleSignIn = GoogleSignIn(       scopes: [         'email',         // Add additional scopes, if you require that data in your Jsonnet mapping       ],     );        SignInWithGoogleButton({super.key, required this.flowId, required this.ory});        void handleGoogleSignIn(GoogleSignInAccount? value) {       value?.authentication.then((value) {         var idToken = value.idToken;         if (idToken == null) {           // If we end up here, but there is no ID token, something went wrong           print("No idToken found");           return;         }            // Create the payload for the updateRegistrationFlow endpoint with the idToken from Google         var body = UpdateRegistrationFlowWithOidcMethod(           (b) => b             ..idToken = idToken             ..method = 'oidc'             ..provider = 'google',         );            // Submit the updateRegistrationFlow endpoint with the payload         ory.getFrontendApi().updateRegistrationFlow(               flow: flowId,               updateRegistrationFlowBody: UpdateRegistrationFlowBody(                   (b) => b..oneOf = OneOf.fromValue1(value: body)),             );       });     }        @override     Widget build(BuildContext context) {       return TextButton(         child: const Text("Sign in with Google"),         onPressed: () => {_googleSignIn.signIn().then(handleGoogleSignIn)},       );     }   }
This code creates a Sign in with Google button and handles the sign-in process. When the button is pressed, the user is prompted to sign in with their Google account. After the user signs in, their ID token is used to update the registration flow. For more detailed information on creating a registration flow in Flutter, you may want to refer to the official Ory documentation or the specific guide for the feature you're interested in. [Source](https://www.ory.sh/docs/kratos/social-signin/google#flutter-code-example)
b
I need to use Passkeys instead
@chilly-king-10285 I need to use passkeys instead
c
A message from kapa.ai
I'm sorry, but the provided knowledge sources do not contain an example of implementing passkeys in Flutter. The available information is about the concept of passkeys, how they are used in passwordless authentication, and how they can be used across multiple devices. Passkeys, as described by the FIDO Alliance, are a password replacement that provides faster, easier, and more secure sign-ins to websites and apps across a user's devices. They allow for passwordless user sign-up and sign-in, creating a safer environment for your system's users who don't have to rely on easily exploitable, legacy authentication methods such as passwords. However, the specific implementation of passkeys in a Flutter application is not covered in the provided sources. For more detailed information, you may want to refer to the official Ory documentation or the specific guide for the feature you're interested in. [Source](https://www.ory.sh/docs/kratos/passwordless/passkeys)
b
@chilly-king-10285 based on I got: DioException [unknown]: null Error: Bad state: No serializer for 'UpdateRegistrationFlowWithPasskeyMethodBuilder'.
Copy code
var body = UpdateRegistrationFlowWithPasskeyMethodBuilder();
      print(body);
      final response = await _ory.updateRegistrationFlow(
        flow: '',
        updateRegistrationFlowBody: UpdateRegistrationFlowBody(  
        (b) => b..oneOf = OneOf.fromValue1(value: body)),     
      );
      print(response);
c
A message from kapa.ai
The error message you're seeing,
No serializer for 'UpdateRegistrationFlowWithPasskeyMethodBuilder'
, suggests that the serialization for
UpdateRegistrationFlowWithPasskeyMethodBuilder
is not defined or not found. In the provided knowledge sources, there is no specific example of using
UpdateRegistrationFlowWithPasskeyMethodBuilder
in Flutter. However, the sources do provide information about the
updateRegistrationFlow
method and its parameters. Here's a general example of how you might use it:
Copy code
dart var body = UpdateRegistrationFlowWithPasskeyMethod(   (b) => b     ..method = 'passkey'     ..passkey_register = 'your_passkey_here'     ..traits = your_traits_object_here     ..transient_payload = your_transient_payload_object_here );  final response = await _ory.updateRegistrationFlow(   flow: 'your_flow_id_here',   updateRegistrationFlowBody: UpdateRegistrationFlowBody(       (b) => b..oneOf = OneOf.fromValue1(value: body)   ), );  print(response);
Please replace
'your_passkey_here'
,
your_traits_object_here
,
your_transient_payload_object_here
, and
'your_flow_id_here'
with your actual values. Please note that this is a basic example and you might need to adjust it according to your needs. For more detailed information, you can refer to the [Ory documentation](https://www.ory.sh/docs/kratos/reference/api#operation/updateRegistrationFlow).
b
@chilly-king-10285 how can I get flow_id via api?
c
A message from kapa.ai
To get a flow ID via API, you need to send a GET request to the appropriate endpoint. The flow ID is stored in the
?flow=
URL query parameter in your application. Here are examples for different types of flows: 1. Login Flow: Send a GET request to the
/self-service/login/flows?id=<flow-id>
endpoint.
Copy code
bash curl -X GET \     -H 'Content-Type: application/json' \     -H 'Accept: application/json' \     -c cookies.txt \     "https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/login/flows?id=<your-flow-id|PROJECT_SLUG.projects.oryapis.com/self-service/login/flows?id=<your-flow-id>>"
[Source](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#get-login-flow) 2. Registration Flow: Send a GET request to the
/self-service/registration/flows?id=<flow-id>
endpoint.
Copy code
bash curl -X GET \     -H 'Content-Type: application/json' \     -H 'Accept: application/json' \     -c cookies.txt \     "https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/registration/flows?id=<your-flow-id|PROJECT_SLUG.projects.oryapis.com/self-service/registration/flows?id=<your-flow-id>>"
[Source](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#get-registration-flow) 3. Recovery Flow: Send a GET request to the
/self-service/recovery/flows?id=<flow-id>
endpoint.
Copy code
bash curl -H 'Content-Type: application/json' \     -H 'Accept: application/json' \     -c cookies.txt \     -b cookies.txt \     "https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/recovery/flows?id=<your-flow-id|PROJECT_SLUG.projects.oryapis.com/self-service/recovery/flows?id=<your-flow-id>>"
[Source](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#get-recovery-flow) 4. Verification Flow: Send a GET request to the
/self-service/verification/flows?id=<flow-id>
endpoint.
Copy code
bash curl -H 'Content-Type: application/json' \     -H 'Accept: application/json' \     -b cookies.txt \     -c cookies.txt \     "https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/verification/flows?id=<your-flow-id|PROJECT_SLUG.projects.oryapis.com/self-service/verification/flows?id=<your-flow-id>>"
[Source](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#get-verification-flow) Please replace
<your-flow-id>
and
$PROJECT_SLUG
with your actual values.
b
var body = UpdateRegistrationFlowWithPasskeyMethod(); I got: Tried to construct class "UpdateRegistrationFlowWithPasskeyMethod" with null for non-nullable field "method".
@chilly-king-10285
c
Sorry @blue-hamburger-51631, I'm not sure what you mean. Please try again. 👋
b
@chilly-king-10285 var body = UpdateRegistrationFlowWithPasskeyMethod(); I got: Tried to construct class "UpdateRegistrationFlowWithPasskeyMethod" with null for non-nullable field "method".
c
A message from kapa.ai
The error message you're seeing suggests that the
method
field, which is non-nullable, is not being set when you're creating an instance of
UpdateRegistrationFlowWithPasskeyMethod
. In the
UpdateRegistrationFlowWithPasskeyMethod
constructor, you need to set the
method
field to
'passkey'
. Here's how you can do it:
Copy code
dart var body = UpdateRegistrationFlowWithPasskeyMethod(   (b) => b     ..method = 'passkey'     // set other fields as necessary );
Please note that you might need to set other fields as necessary according to your needs. For more detailed information, you can refer to the [Ory documentation](https://www.ory.sh/docs/kratos/reference/api#operation/updateRegistrationFlow).
b
@chilly-king-10285 I am getting: DioException [unknown]: null Error: Deserializing to 'SuccessfulNativeRegistration' failed due to: Tried to build class "SuccessfulNativeRegistration" but nested builder for field "identity" threw: Tried to construct class "Identity" with null for non-nullable field "id". on final response = await _ory.updateRegistrationFlow( flow: native.data!.id, updateRegistrationFlowBody: UpdateRegistrationFlowBody( (b) => b..oneOf = OneOf.fromValue1(value: body)), );
c
A message from kapa.ai
The error message you're seeing suggests that the
id
field of the
Identity
object is null when the
SuccessfulNativeRegistration
object is being deserialized. This field is non-nullable, so it must have a value. The
updateRegistrationFlow
method returns a
SuccessfulNativeRegistration
object, which includes an
Identity
object. The
Identity
object should have an
id
field that is automatically set by the Ory server. Here's the general structure of a
SuccessfulNativeRegistration
object:
Copy code
dart class SuccessfulNativeRegistration {   final Identity identity;   final Session session;   // other fields... }
And here's the general structure of an
Identity
object:
Copy code
dart class Identity {   final String id;   // other fields... }
If the
id
field is null, it might be because the registration flow was not completed successfully, or there was an issue with the Ory server. To troubleshoot this issue, you can: 1. Check the status of the Ory server to make sure it's running correctly. 2. Make sure the registration flow is being completed successfully before you call the
updateRegistrationFlow
method. 3. Check the
native.data!.id
value to make sure it's not null before you call the
updateRegistrationFlow
method. If the issue persists, you may want to refer to the official Ory documentation or seek help from the Ory community. [Source](https://www.ory.sh/docs/kratos/reference/api#operation/updateRegistrationFlow)