mirror of
https://github.com/TeamPiped/piped_dart.git
synced 2024-08-14 22:27:49 +00:00
38 lines
1 KiB
Dart
38 lines
1 KiB
Dart
|
//
|
||
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||
|
//
|
||
|
|
||
|
import 'dart:convert';
|
||
|
|
||
|
import 'package:dio/dio.dart';
|
||
|
import 'package:piped_api/src/auth/auth.dart';
|
||
|
|
||
|
class BasicAuthInfo {
|
||
|
final String username;
|
||
|
final String password;
|
||
|
|
||
|
const BasicAuthInfo(this.username, this.password);
|
||
|
}
|
||
|
|
||
|
class BasicAuthInterceptor extends AuthInterceptor {
|
||
|
final Map<String, BasicAuthInfo> authInfo = {};
|
||
|
|
||
|
@override
|
||
|
void onRequest(
|
||
|
RequestOptions options,
|
||
|
RequestInterceptorHandler handler,
|
||
|
) {
|
||
|
final metadataAuthInfo = getAuthInfo(options, (secure) => (secure['type'] == 'http' && secure['scheme'] == 'basic') || secure['type'] == 'basic');
|
||
|
for (final info in metadataAuthInfo) {
|
||
|
final authName = info['name'] as String;
|
||
|
final basicAuthInfo = authInfo[authName];
|
||
|
if (basicAuthInfo != null) {
|
||
|
final basicAuth = 'Basic ${base64Encode(utf8.encode('${basicAuthInfo.username}:${basicAuthInfo.password}'))}';
|
||
|
options.headers['Authorization'] = basicAuth;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
super.onRequest(options, handler);
|
||
|
}
|
||
|
}
|