31 lines
885 B
Dart
31 lines
885 B
Dart
|
import 'package:grpc/grpc.dart';
|
||
|
|
||
|
import 'generated/smm_core.pbgrpc.dart';
|
||
|
|
||
|
class AuthenticationInterceptor extends ClientInterceptor {
|
||
|
Future<void> _provider(Map<String, String> metadata, String uri) async {
|
||
|
metadata['Authorization'] = "Y3JhYjpjcmFi";
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
ResponseFuture<R> interceptUnary<Q, R>(
|
||
|
ClientMethod<Q, R> method, Q request, CallOptions options, invoker) {
|
||
|
return super.interceptUnary(method, request,
|
||
|
options.mergedWith(CallOptions(providers: [_provider])), invoker);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class SmmCoreTerminalClient {
|
||
|
late final ClientChannel channel;
|
||
|
late final SmmCoreClient stub;
|
||
|
|
||
|
SmmCoreTerminalClient() {
|
||
|
channel = ClientChannel(
|
||
|
'0.0.0.0',
|
||
|
port: 8080,
|
||
|
options: ChannelOptions(credentials: ChannelCredentials.insecure()),
|
||
|
);
|
||
|
stub = SmmCoreClient(channel, interceptors: [AuthenticationInterceptor()]);
|
||
|
}
|
||
|
}
|