Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit be242fa

Browse files
committed
Address PR comments / checks.
1 parent affd29c commit be242fa

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:convert';
6+
7+
import 'package:google_identity_services_web/id.dart';
8+
import 'package:jose/jose.dart';
9+
10+
import 'jsify_as.dart';
11+
12+
/// Wraps a key-value map of [claims] in a JWT token similar GIS'.
13+
///
14+
/// Note that the encryption of this token is weak, and this method should
15+
/// only be used for tests!
16+
CredentialResponse createJwt(Map<String, Object?>? claims) {
17+
String? credential;
18+
if (claims != null) {
19+
final JsonWebTokenClaims token = JsonWebTokenClaims.fromJson(claims);
20+
final JsonWebSignatureBuilder builder = JsonWebSignatureBuilder();
21+
builder.jsonContent = token.toJson();
22+
builder.addRecipient(
23+
JsonWebKey.fromJson(<String, Object?>{
24+
'kty': 'oct',
25+
'k': base64.encode('symmetric-encryption-is-weak'.codeUnits),
26+
}),
27+
algorithm: 'HS256'); // bogus crypto, don't use this for prod!
28+
builder.setProtectedHeader('typ', 'JWT');
29+
credential = builder.build().toCompactSerialization();
30+
}
31+
return jsifyAs<CredentialResponse>(<String, Object?>{
32+
'credential': credential,
33+
});
34+
}

packages/google_sign_in/google_sign_in_web/example/integration_test/utils_test.dart

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:convert';
6-
75
import 'package:flutter_test/flutter_test.dart';
86
import 'package:google_identity_services_web/id.dart';
97
import 'package:google_identity_services_web/oauth2.dart';
108
import 'package:google_sign_in_platform_interface/google_sign_in_platform_interface.dart';
119
import 'package:google_sign_in_web/src/utils.dart';
1210
import 'package:integration_test/integration_test.dart';
13-
import 'package:jose/jose.dart';
1411

12+
import 'src/create_jwt.dart';
1513
import 'src/jsify_as.dart';
1614

1715
void main() {
@@ -80,25 +78,3 @@ void main() {
8078
});
8179
});
8280
}
83-
84-
CredentialResponse createJwt(Map<String, Object?>? claims) {
85-
String? credential;
86-
if (claims != null) {
87-
final JsonWebTokenClaims token = JsonWebTokenClaims.fromJson(claims);
88-
final JsonWebSignatureBuilder builder = JsonWebSignatureBuilder();
89-
builder.jsonContent = token.toJson();
90-
builder.addRecipient(
91-
JsonWebKey.fromJson(<String, Object?>{
92-
'kty': 'oct',
93-
'k': base64.encode('symmetric-encryption-is-weak'.codeUnits),
94-
}),
95-
algorithm: 'HS256'); // bogus crypto, don't use this for prod!
96-
builder.setProtectedHeader('typ', 'JWT');
97-
credential = builder.build().toCompactSerialization();
98-
// ignore:avoid_print
99-
print('Generated JWT: $credential');
100-
}
101-
return jsifyAs<CredentialResponse>(<String, Object?>{
102-
'credential': credential,
103-
});
104-
}

packages/google_sign_in/google_sign_in_web/lib/src/gis_client.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class GisSdkClient {
199199
// If we already know the user, use their `email` as a `hint`, so they don't
200200
// have to pick their user again in the Authorization popup.
201201
final GoogleSignInUserData? knownUser =
202-
utils.gisResponsesToUserData(_lastCredentialResponse);
202+
utils.gisResponsesToUserData(_lastCredentialResponse);
203203
// This toggles a popup, so `signIn` *must* be called with
204204
// user activation.
205205
_tokenClient.requestAccessToken(OverridableTokenClientConfig(
@@ -287,7 +287,7 @@ class GisSdkClient {
287287

288288
// The scopes initially requested by the developer.
289289
//
290-
// We store this because we might need to add more at `signIn`, if the user
290+
// We store this because we might need to add more at `signIn`. If the user
291291
// doesn't `silentSignIn`, we expand this list to consult the People API to
292292
// return some basic Authentication information.
293293
final List<String> _initialScopes;

0 commit comments

Comments
 (0)