Skip to content

Commit

Permalink
fixing issue with custom headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasroussel committed Nov 5, 2023
1 parent 44e2815 commit 881fe9a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.12.1

- Fixing issue with custom headers (https://github.com/jonasroussel/dart_jsonwebtoken/issues/48)

## 2.12.0

- **NEW:** tests have been added
Expand Down
9 changes: 5 additions & 4 deletions lib/src/jwt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ class JWT {
bool noIssueAt = false,
}) {
try {
header ??= {};
header!.addAll({'alg': algorithm.name, 'typ': 'JWT'});

if (payload is Map<String, dynamic> || payload is Map<dynamic, dynamic>) {
try {
payload = Map<String, dynamic>.from(payload);
Expand All @@ -287,7 +284,11 @@ class JWT {
}
}

final b64Header = base64Unpadded(jsonBase64.encode(header));
final tokenHeader = Map.from(header ?? {});
tokenHeader.putIfAbsent('alg', () => algorithm.name);
tokenHeader.putIfAbsent('typ', () => 'JWT');

final b64Header = base64Unpadded(jsonBase64.encode(tokenHeader));

String b64Payload;
try {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_jsonwebtoken
description: A dart implementation of the famous javascript library 'jsonwebtoken' (JWT).
version: 2.12.0
version: 2.12.1
repository: https://github.com/jonasroussel/dart_jsonwebtoken
homepage: https://github.com/jonasroussel/dart_jsonwebtoken#readme

Expand Down

0 comments on commit 881fe9a

Please sign in to comment.