-
-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add documentation for native Google SDK social sign in (#1540)
* feat: add documentation for native Google SDK social sign in * chore: cleanup * chore: cr
- Loading branch information
1 parent
ac8f73c
commit 2584e8d
Showing
4 changed files
with
112 additions
and
7 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
code-examples/sdk/dart/social-sign-in/sign-in-with-google.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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; | ||
|
||
// highlight-start | ||
final GoogleSignIn _googleSignIn = GoogleSignIn( | ||
scopes: [ | ||
'email', | ||
// Add additional scopes, if you require that data in your Jsonnet mapping | ||
], | ||
); | ||
// highlight-end | ||
|
||
SignInWithGoogleButton({super.key, required this.flowId, required this.ory}); | ||
|
||
// highlight-start | ||
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)), | ||
); | ||
}); | ||
} | ||
// highlight-end | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return TextButton( | ||
child: const Text("Sign in with Google"), | ||
onPressed: () => {_googleSignIn.signIn().then(handleGoogleSignIn)}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters