Regenerate and update.

This commit is contained in:
Kavin 2022-06-05 09:34:50 +01:00
parent 4ab4098c9a
commit 8d3d6d14b0
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
21 changed files with 2130 additions and 83 deletions

View file

@ -0,0 +1,33 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.7
// ignore_for_file: unused_import
import 'dart:async';
import 'package:piped_api/auth/auth.dart';
import 'package:dio/dio.dart';
class ApiKeyAuthInterceptor extends AuthInterceptor {
Map<String, String> apiKeys = {};
@override
Future<dynamic> onRequest(RequestOptions options) {
final authInfo = getAuthInfo(options, 'apiKey');
for (final info in authInfo) {
final authName = info['name'] as String;
final authKeyName = info['keyName'] as String;
final authWhere = info['where'] as String;
final apiKey = apiKeys[authName];
if (apiKey != null) {
if (authWhere == 'query') {
options.queryParameters[authKeyName] = apiKey;
} else {
options.headers[authKeyName] = apiKey;
}
}
}
return super.onRequest(options);
}
}

27
lib/auth/auth.dart Normal file
View file

@ -0,0 +1,27 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.7
// ignore_for_file: unused_import
import 'package:dio/dio.dart';
abstract class AuthInterceptor extends Interceptor {
/// Get auth information on given route for the given type.
/// Can return an empty list if type is not present on auth data or
/// if route doesn't need authentication.
List<Map<String, dynamic>> getAuthInfo(RequestOptions route, String type) {
if (route.extra.containsKey('secure')) {
final auth = route.extra['secure'] as List<Map<String, String>>;
final results = <Map<String, dynamic>>[];
for (final info in auth) {
if (info['type'] == type) {
results.add(info);
}
}
return results;
}
return [];
}
}

38
lib/auth/basic_auth.dart Normal file
View file

@ -0,0 +1,38 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.7
// ignore_for_file: unused_import
import 'dart:async';
import 'dart:convert';
import 'package:piped_api/auth/auth.dart';
import 'package:dio/dio.dart';
class BasicAuthInfo {
final String username;
final String password;
const BasicAuthInfo(this.username, this.password);
}
class BasicAuthInterceptor extends AuthInterceptor {
Map<String, BasicAuthInfo> authInfo = {};
@override
Future<dynamic> onRequest(RequestOptions options) {
final metadataAuthInfo = getAuthInfo(options, '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;
}
}
return super.onRequest(options);
}
}

27
lib/auth/oauth.dart Normal file
View file

@ -0,0 +1,27 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.7
// ignore_for_file: unused_import
import 'dart:async';
import 'package:piped_api/auth/auth.dart';
import 'package:dio/dio.dart';
class OAuthInterceptor extends AuthInterceptor {
Map<String, String> tokens = {};
@override
Future<dynamic> onRequest(RequestOptions options) {
final authInfo = getAuthInfo(options, 'oauth');
for (final info in authInfo) {
final token = tokens[info['name']];
if (token != null) {
options.headers['Authorization'] = 'Bearer ${token}';
break;
}
}
return super.onRequest(options);
}
}