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

Add the option to specify a port for the local server. #5

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/google_sign_in_dartio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform {
required String clientId,
required UrlPresenter presenter,
String? exchangeEndpoint,
int? port,
}) : _storage = storage,
_clientId = clientId,
presenter = presenter,
_port = port,
_exchangeEndpoint = exchangeEndpoint;

/// Registers this implementation as default implementation for GoogleSignIn
Expand All @@ -48,6 +50,7 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform {
String? exchangeEndpoint,
DataStorage? storage,
UrlPresenter? presenter,
int? port,
}) async {
presenter ??= (Uri uri) => launch(uri.toString());

Expand All @@ -72,12 +75,14 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform {
storage: storage,
exchangeEndpoint: exchangeEndpoint,
clientId: clientId,
port: port,
);
}

final String? _exchangeEndpoint;
final String _clientId;
final DataStorage _storage;
final int? _port;

late List<String> _scopes;
String? _hostedDomain;
Expand Down Expand Up @@ -281,6 +286,7 @@ class GoogleSignInDart extends platform.GoogleSignInPlatform {
hostedDomains: _hostedDomain,
presenter: presenter,
uid: _storage.id,
port: _port,
);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/src/token_sign_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Future<Map<String, dynamic>> _tokenSignIn({
required UrlPresenter presenter,
String? hostedDomains,
String? uid,
int? port,
}) async {
final Completer<Map<String, dynamic>> completer =
Completer<Map<String, dynamic>>();
Expand All @@ -26,8 +27,8 @@ Future<Map<String, dynamic>> _tokenSignIn({
_deriveCodeVerifierChallenge(codeVerifier);

final InternetAddress address = InternetAddress.loopbackIPv4;
final HttpServer server = await HttpServer.bind(address, 0);
final int port = server.port;
final HttpServer server = await HttpServer.bind(address, port ?? 0);
port = port ?? server.port;
server.listen((HttpRequest request) async {
final Uri uri = request.requestedUri;

Expand Down