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

Commit 2bed955

Browse files
authored
Adds the two GitHub OAuth endpoints to enable GitHub auth for dart-pad. (#866)
1 parent 8c77a6e commit 2bed955

File tree

6 files changed

+456
-0
lines changed

6 files changed

+456
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
Google Inc.
77
George Moschovitis <[email protected]>
8+
Tim Maffett <[email protected]>

lib/services_cloud_run.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:shelf/shelf_io.dart' as shelf;
1515

1616
import 'src/common_server_api.dart';
1717
import 'src/common_server_impl.dart';
18+
import 'src/github_oauth_handler.dart';
1819
import 'src/sdk.dart';
1920
import 'src/server_cache.dart';
2021
import 'src/shelf_cors.dart' as shelf_cors;
@@ -61,6 +62,8 @@ Future<void> main(List<String> args) async {
6162
Cloud Run Environment variables:
6263
$cloudRunEnvVars''');
6364

65+
await GitHubOAuthHandler.initFromEnvironmentalVars();
66+
6467
await EndpointsServer.serve(port, redisServerUri, sdk);
6568
_logger.info('Listening on port $port');
6669
}
@@ -103,6 +106,18 @@ class EndpointsServer {
103106
);
104107
commonServerApi = CommonServerApi(_commonServerImpl);
105108

109+
// Set cache for GitHub OAuth and add GitHub OAuth routes to our router.
110+
GitHubOAuthHandler.setCache(redisServerUri == null
111+
? InMemoryCache()
112+
: RedisCache(
113+
redisServerUri,
114+
sdk,
115+
// The name of the Cloud Run revision being run, for more detail please see:
116+
// https://cloud.google.com/run/docs/reference/container-contract#env-vars
117+
Platform.environment['K_REVISION'],
118+
));
119+
GitHubOAuthHandler.addRoutes(commonServerApi.router);
120+
106121
pipeline = const Pipeline()
107122
.addMiddleware(logRequests())
108123
.addMiddleware(_createCustomCorsHeadersMiddleware());

lib/services_dev.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:shelf/shelf_io.dart' as shelf;
1515

1616
import 'src/common_server_api.dart';
1717
import 'src/common_server_impl.dart';
18+
import 'src/github_oauth_handler.dart';
1819
import 'src/sdk.dart';
1920
import 'src/server_cache.dart';
2021
import 'src/shelf_cors.dart' as shelf_cors;
@@ -43,6 +44,8 @@ Future<void> main(List<String> args) async {
4344
if (record.stackTrace != null) print(record.stackTrace);
4445
});
4546

47+
await GitHubOAuthHandler.initFromEnvironmentalVars();
48+
4649
await EndpointsServer.serve(port, Sdk.create(result['channel'] as String),
4750
result['null-safety'] as bool);
4851
_logger.info('Listening on port $port');
@@ -69,6 +72,10 @@ class EndpointsServer {
6972
commonServerApi = CommonServerApi(commonServerImpl);
7073
commonServerImpl.init();
7174

75+
// Set cache for GitHub OAuth and add GitHub OAuth routes to our router.
76+
GitHubOAuthHandler.setCache(InMemoryCache());
77+
GitHubOAuthHandler.addRoutes(commonServerApi.router);
78+
7279
pipeline = const Pipeline()
7380
.addMiddleware(logRequests())
7481
.addMiddleware(_createCustomCorsHeadersMiddleware());

0 commit comments

Comments
 (0)