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

Remove allowInterop calls, fix types of callbacks, and use dart:js_interop #655

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions googleapis_auth/lib/src/oauth2_flows/token_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';
import 'dart:html';
import 'dart:js';
import 'dart:js_interop';

import 'package:google_identity_services_web/loader.dart' as gis_loader;
import 'package:google_identity_services_web/oauth2.dart' as gis;
Expand All @@ -10,8 +10,12 @@ import '../access_token.dart';
import '../authentication_exception.dart';
import '../utils.dart';

JsObject get _googleAccountsId =>
((context['google'] as JsObject)['accounts'] as JsObject)['id'] as JsObject;
@JS('google.accounts.id')
external _GoogleAccountsId get _googleAccountsId;

extension type _GoogleAccountsId._(JSObject _) implements JSObject {
external void setLogLevel(String logLevel);
}

/// Obtains [AccessCredentials] using the
/// [Google Identity Services](https://developers.google.com/identity/oauth2/web/guides/overview)
Expand All @@ -37,7 +41,7 @@ Future<AccessCredentials> requestAccessCredentials({
String? logLevel,
}) async {
await gis_loader.loadWebSdk();
if (logLevel != null) _googleAccountsId.callMethod('setLogLevel', [logLevel]);
if (logLevel != null) _googleAccountsId.setLogLevel(logLevel);

final completer = Completer<AccessCredentials>();

Expand Down Expand Up @@ -79,11 +83,11 @@ Future<AccessCredentials> requestAccessCredentials({
}

final config = gis.TokenClientConfig(
callback: allowInterop(callback),
callback: callback,
client_id: clientId,
scope: scopes.toList(),
prompt: prompt,
error_callback: allowInterop(errorCallback),
error_callback: errorCallback,
);

final client = gis.oauth2.initTokenClient(config);
Expand Down Expand Up @@ -115,7 +119,7 @@ Future<CodeResponse> requestAuthorizationCode({
String? logLevel,
}) async {
await gis_loader.loadWebSdk();
if (logLevel != null) _googleAccountsId.callMethod('setLogLevel', [logLevel]);
if (logLevel != null) _googleAccountsId.setLogLevel(logLevel);

final completer = Completer<CodeResponse>();

Expand Down Expand Up @@ -153,13 +157,13 @@ Future<CodeResponse> requestAuthorizationCode({
}

final config = gis.CodeClientConfig(
callback: allowInterop(callback),
callback: callback,
client_id: clientId,
scope: scopes.toList(),
state: state,
login_hint: hint,
hd: hostedDomain,
error_callback: allowInterop(errorCallback),
error_callback: errorCallback,
);

final client = gis.oauth2.initCodeClient(config);
Expand All @@ -175,12 +179,14 @@ Future<CodeResponse> requestAuthorizationCode({
Future<void> revokeConsent(String accessTokenValue) {
final completer = Completer<void>();

void done(Object? arg) {
void done(JSAny? arg) {
window.console.log(arg);
completer.complete();
}

gis.oauth2.revoke(accessTokenValue, allowInterop(done));
// TODO(srujzs): Once `TokenRevocationResponse` is an extension type that
srujzs marked this conversation as resolved.
Show resolved Hide resolved
// extends `JSObject`, this cast can be removed.
gis.oauth2.revoke(accessTokenValue, done as gis.RevokeTokenDoneFn);

return completer.future;
}
Expand Down
Loading