withOAuth static method
Yt
withOAuth({
- ClientId? oAuthClientId,
- LogOptions logOptions = const LogOptions(LogLevel.error, stackTraceLevel: LogLevel.off),
Implementation
static Yt withOAuth(
{ClientId? oAuthClientId,
LogOptions logOptions = const LogOptions(
LogLevel.error,
stackTraceLevel: LogLevel.off,
)}) {
final yt = Yt(
logOptions: logOptions,
printer: const PrettyPrinter(
showColors: false,
));
addInterceptor(InterceptorsWrapper(onRequest: (options, handler) async {
final oauthAccessControl = OAuthAccessControl(oAuthClientId);
await oauthAccessControl.checkAccessToken();
options.headers['Authorization'] = 'Bearer ${oauthAccessControl.token}';
return handler.next(options);
}));
yt.setModules(useTokenAuth: true);
dio.interceptors.addAll(_interceptors);
return yt;
}