-
Notifications
You must be signed in to change notification settings - Fork 141
fix(ui_oauth): replace desktop_webview_auth with flutter_web_auth_2 #693
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
Open
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1667717
fix(ui_oauth): replace desktop_webview_auth with flutter_web_auth_2
demolaf 7c2e3db
fix(ui_oauth): fix macOS callback matching and Twitter OAuth1.0a signing
demolaf 8767888
fix(ui_oauth): bump example's macOS deployment target
demolaf 1031f1d
fix(ui_oauth): validate Facebook OAuth state and fix nonce charset
demolaf 71558bd
fix(ui_oauth): pin androidx.browser to fix android e2e, improve error…
demolaf 698b91d
fix(ui_oauth): pin remaining androidx transitive deps for android e2e
demolaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,18 @@ | ||
| // Copyright 2022, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| /// The result of a desktop OAuth sign-in flow. | ||
| class AuthResult { | ||
| final String? accessToken; | ||
| final String? idToken; | ||
| final String? tokenSecret; | ||
|
|
||
| const AuthResult({this.accessToken, this.idToken, this.tokenSecret}); | ||
|
|
||
| @override | ||
| String toString() { | ||
| return 'AuthResult(idToken: $idToken, accessToken: $accessToken, ' | ||
| 'tokenSecret: $tokenSecret)'; | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
packages/firebase_ui_oauth/lib/src/oauth/facebook_sign_in_args.dart
This file contains hidden or 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 @@ | ||
| // Copyright 2022, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'auth_result.dart'; | ||
| import 'oauth_util.dart'; | ||
| import 'provider_args.dart'; | ||
|
|
||
| const _responseType = 'token'; | ||
|
|
||
| class FacebookSignInArgs extends ProviderArgs { | ||
| final String clientId; | ||
|
|
||
| @override | ||
| final String redirectUri; | ||
|
|
||
| @override | ||
| final host = 'www.facebook.com'; | ||
|
|
||
| @override | ||
| final path = '/v12.0/dialog/oauth'; | ||
|
|
||
| FacebookSignInArgs({required this.clientId, required this.redirectUri}); | ||
|
|
||
| String state = ''; | ||
|
|
||
| @override | ||
| Map<String, String> buildQueryParameters() { | ||
| state = generateNonce(); | ||
|
|
||
| return { | ||
| 'client_id': clientId, | ||
| 'redirect_uri': redirectUri, | ||
| 'state': state, | ||
| 'response_type': _responseType, | ||
| }; | ||
| } | ||
|
|
||
| /// Validates the `state` echoed back by Facebook against the one sent in | ||
| /// [buildQueryParameters] before accepting the callback, to guard against | ||
| /// CSRF: an attacker tricking the app into completing a sign-in the user | ||
| /// never started. | ||
| @override | ||
| Future<AuthResult?> authorizeFromCallback(String callbackUrl) async { | ||
| final uri = Uri.parse(callbackUrl); | ||
| final args = usesFragment | ||
| ? Uri.splitQueryString(uri.fragment) | ||
| : uri.queryParameters; | ||
|
|
||
| if (args['state'] != state) { | ||
| throw Exception('OAuth state mismatch, possible CSRF attempt'); | ||
| } | ||
|
|
||
| return super.authorizeFromCallback(callbackUrl); | ||
| } | ||
| } | ||
44 changes: 44 additions & 0 deletions
44
packages/firebase_ui_oauth/lib/src/oauth/google_sign_in_args.dart
This file contains hidden or 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,44 @@ | ||
| // Copyright 2022, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'oauth_util.dart'; | ||
| import 'provider_args.dart'; | ||
|
|
||
| const _defaultSignInScope = 'https://www.googleapis.com/auth/plus.login'; | ||
|
|
||
| class GoogleSignInArgs extends ProviderArgs { | ||
| final String clientId; | ||
| final String scope; | ||
| final bool immediate; | ||
| final String responseType; | ||
|
|
||
| @override | ||
| final String redirectUri; | ||
|
|
||
| @override | ||
| final host = 'accounts.google.com'; | ||
|
|
||
| @override | ||
| final path = '/o/oauth2/v2/auth'; | ||
|
|
||
| GoogleSignInArgs({ | ||
| required this.clientId, | ||
| required this.redirectUri, | ||
| this.scope = _defaultSignInScope, | ||
| this.immediate = false, | ||
| this.responseType = 'token id_token', | ||
| }); | ||
|
|
||
| @override | ||
| Map<String, String> buildQueryParameters() { | ||
| return { | ||
| 'client_id': clientId, | ||
| 'scope': scope, | ||
| 'immediate': immediate.toString(), | ||
| 'response_type': responseType, | ||
| 'redirect_uri': redirectUri, | ||
| 'nonce': generateNonce(), | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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,18 @@ | ||
| // Copyright 2022, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'dart:math'; | ||
|
|
||
| /// Generates a cryptographically secure random nonce, to be included in a | ||
| /// credential request. | ||
| String generateNonce([int length = 32]) { | ||
| const chars = | ||
| '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | ||
| final random = Random.secure(); | ||
|
|
||
| return List.generate( | ||
| length, | ||
| (_) => chars[random.nextInt(chars.length)], | ||
| ).join(); | ||
| } |
48 changes: 48 additions & 0 deletions
48
packages/firebase_ui_oauth/lib/src/oauth/provider_args.dart
This file contains hidden or 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,48 @@ | ||
| // Copyright 2022, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'auth_result.dart'; | ||
|
|
||
| /// Describes how to build the sign-in URL for a desktop OAuth flow, and how | ||
| /// to turn the resulting callback URL into an [AuthResult]. | ||
| abstract class ProviderArgs { | ||
| String get redirectUri; | ||
| String get host; | ||
| String get path; | ||
|
|
||
| Map<String, String> buildQueryParameters(); | ||
|
|
||
| Future<String> buildSignInUri() async { | ||
| final uri = Uri( | ||
| scheme: 'https', | ||
| host: host, | ||
| path: path, | ||
| queryParameters: buildQueryParameters(), | ||
| ); | ||
|
|
||
| return uri.toString(); | ||
| } | ||
|
|
||
| bool usesFragment = true; | ||
|
|
||
| Future<AuthResult?> authorizeFromCallback(String callbackUrl) async { | ||
| final uri = Uri.parse(callbackUrl); | ||
| late Map<String, String> args; | ||
|
|
||
| if (usesFragment) { | ||
| args = Uri.splitQueryString(uri.fragment); | ||
| } else { | ||
| args = uri.queryParameters; | ||
| } | ||
|
|
||
| if (args.containsKey('access_token') || args.containsKey('id_token')) { | ||
| return AuthResult( | ||
| accessToken: args['access_token'], | ||
| idToken: args['id_token'], | ||
| ); | ||
| } | ||
|
|
||
| throw Exception('No access token found'); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.