Line data Source code
1 : import 'package:flutter/foundation.dart';
2 :
3 : /// Configuration for automatic token refresh.
4 : ///
5 : /// When a worker receives a 401 Unauthorized response, it can automatically
6 : /// attempt to refresh the access token using this configuration.
7 : @immutable
8 : final class TokenRefreshConfig {
9 : /// Create a token refresh configuration.
10 1 : const TokenRefreshConfig({
11 : required this.url,
12 : this.method = 'POST',
13 : this.headers = const {},
14 : this.body = const {},
15 : this.responseKey = 'access_token',
16 : this.tokenHeaderName = 'Authorization',
17 : this.tokenPrefix = 'Bearer ',
18 : });
19 :
20 : /// The URL to call for token refresh.
21 : final String url;
22 :
23 : /// HTTP method for the refresh request (default: POST).
24 : final String method;
25 :
26 : /// HTTP headers for the refresh request.
27 : final Map<String, String> headers;
28 :
29 : /// HTTP body for the refresh request (usually containing refresh_token).
30 : final Map<String, dynamic> body;
31 :
32 : /// Key in the JSON response that contains the new access token.
33 : /// Supports nested keys using dot notation (e.g. "auth.access_token").
34 : final String responseKey;
35 :
36 : /// Name of the header where the new token should be placed in retried requests.
37 : final String tokenHeaderName;
38 :
39 : /// Prefix for the token in the header (default: "Bearer ").
40 : final String tokenPrefix;
41 :
42 : /// Convert to map for platform channel.
43 4 : Map<String, dynamic> toMap() => {
44 2 : 'url': url,
45 2 : 'method': method,
46 2 : 'headers': headers,
47 2 : 'body': body,
48 2 : 'responseKey': responseKey,
49 2 : 'tokenHeaderName': tokenHeaderName,
50 2 : 'tokenPrefix': tokenPrefix,
51 : };
52 :
53 0 : @override
54 0 : String toString() => 'TokenRefreshConfig(url: $url, method: $method)';
55 : }
|