Line data Source code
1 : import 'package:flutter/foundation.dart';
2 :
3 : /// Authentication configuration for HTTP workers.
4 : ///
5 : /// Provides a declarative way to configure auth headers for download and
6 : /// upload workers. The [accessToken] is injected into the [headerTemplate]
7 : /// wherever `{accessToken}` appears.
8 : ///
9 : /// ## Example — Bearer token
10 : /// ```dart
11 : /// worker: NativeWorker.httpDownload(
12 : /// url: 'https://api.example.com/files/secret.pdf',
13 : /// savePath: '/tmp/secret.pdf',
14 : /// authToken: myToken,
15 : /// ),
16 : /// ```
17 : ///
18 : /// ## Example — Custom header format
19 : /// ```dart
20 : /// worker: NativeWorker.httpDownload(
21 : /// url: 'https://api.example.com/files/secret.pdf',
22 : /// savePath: '/tmp/secret.pdf',
23 : /// authToken: myApiKey,
24 : /// authHeaderTemplate: 'ApiKey {accessToken}',
25 : /// ),
26 : /// ```
27 : @immutable
28 : class AuthConfig {
29 0 : const AuthConfig({
30 : required this.accessToken,
31 : this.headerTemplate = 'Bearer {accessToken}',
32 : });
33 :
34 : /// The access token value.
35 : final String accessToken;
36 :
37 : /// Template string for the `Authorization` header value.
38 : ///
39 : /// `{accessToken}` is replaced with [accessToken] at request time.
40 : /// Default: `"Bearer {accessToken}"`
41 : final String headerTemplate;
42 :
43 : /// Resolved header value with [accessToken] substituted.
44 0 : String get resolvedHeader =>
45 0 : headerTemplate.replaceAll('{accessToken}', accessToken);
46 : }
|