mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Omit Authorization header when API key is empty
Send no Authorization header at all on a fresh install (rather than "Bearer " with an empty token), so the backend can distinguish "no credentials supplied" from "credentials supplied but invalid". Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
b5da90be59
commit
8e9e221048
@@ -105,16 +105,20 @@ class BackendAPI {
|
|||||||
PrefUtil.getValue("base_url", "http://localhost:3000/api") as String;
|
PrefUtil.getValue("base_url", "http://localhost:3000/api") as String;
|
||||||
_apiKey = XOR().xorDecode(PrefUtil.getValue("api_key", "") as String);
|
_apiKey = XOR().xorDecode(PrefUtil.getValue("api_key", "") as String);
|
||||||
|
|
||||||
|
final headers = <String, String>{
|
||||||
|
HttpHeaders.contentTypeHeader: 'application/json',
|
||||||
|
};
|
||||||
|
if (_apiKey.isNotEmpty) {
|
||||||
|
headers[HttpHeaders.authorizationHeader] = 'Bearer $_apiKey';
|
||||||
|
}
|
||||||
|
|
||||||
_dio = Dio(
|
_dio = Dio(
|
||||||
BaseOptions(
|
BaseOptions(
|
||||||
baseUrl: _baseUrl,
|
baseUrl: _baseUrl,
|
||||||
connectTimeout: _connectTimeout,
|
connectTimeout: _connectTimeout,
|
||||||
receiveTimeout: _receiveTimeout,
|
receiveTimeout: _receiveTimeout,
|
||||||
sendTimeout: _sendTimeout,
|
sendTimeout: _sendTimeout,
|
||||||
headers: {
|
headers: headers,
|
||||||
HttpHeaders.contentTypeHeader: 'application/json',
|
|
||||||
HttpHeaders.authorizationHeader: 'Bearer $_apiKey',
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
_dio.interceptors.add(_buildRetryInterceptor(_dio));
|
_dio.interceptors.add(_buildRetryInterceptor(_dio));
|
||||||
@@ -127,16 +131,20 @@ class BackendAPI {
|
|||||||
|
|
||||||
// Returns null if the test was successful, and a String with a message about the issue if not
|
// Returns null if the test was successful, and a String with a message about the issue if not
|
||||||
static Future<String?> test(String baseUrl, String apiKey) async {
|
static Future<String?> test(String baseUrl, String apiKey) async {
|
||||||
|
final headers = <String, String>{
|
||||||
|
HttpHeaders.contentTypeHeader: 'application/json',
|
||||||
|
};
|
||||||
|
if (apiKey.isNotEmpty) {
|
||||||
|
headers[HttpHeaders.authorizationHeader] = 'Bearer $apiKey';
|
||||||
|
}
|
||||||
|
|
||||||
Dio dio = Dio(
|
Dio dio = Dio(
|
||||||
BaseOptions(
|
BaseOptions(
|
||||||
baseUrl: baseUrl,
|
baseUrl: baseUrl,
|
||||||
connectTimeout: _connectTimeout,
|
connectTimeout: _connectTimeout,
|
||||||
receiveTimeout: _receiveTimeout,
|
receiveTimeout: _receiveTimeout,
|
||||||
sendTimeout: _sendTimeout,
|
sendTimeout: _sendTimeout,
|
||||||
headers: {
|
headers: headers,
|
||||||
HttpHeaders.contentTypeHeader: 'application/json',
|
|
||||||
HttpHeaders.authorizationHeader: 'Bearer $apiKey',
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
|
|||||||
Reference in New Issue
Block a user