-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow dynamic "Encryption Key" value in service
- Loading branch information
1 parent
12136a5
commit 22dc10f
Showing
4 changed files
with
28 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import 'package:chopper/chopper.dart'; | ||
|
||
/// Sets the "X-Encryption-Key" and "Accept": "application/json" values. | ||
class AutogramAuthenticator extends HeadersInterceptor { | ||
AutogramAuthenticator({required String encryptionKey}) | ||
: super({ | ||
"Accept": "application/json", | ||
"X-Encryption-Key": encryptionKey, | ||
}); | ||
final String Function() encryptionKeySource; | ||
|
||
AutogramAuthenticator(this.encryptionKeySource) : super(const {}); | ||
|
||
@override | ||
Future<Request> onRequest(Request request) async { | ||
final encryptionKey = encryptionKeySource(); | ||
final allHeaders = { | ||
"Accept": "application/json", | ||
"X-Encryption-Key": encryptionKey, | ||
}; | ||
|
||
return applyHeaders(request, allHeaders); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters