Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jwt typ #86

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/web5/lib/src/jwt/jwt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class Jwt {
static Future<String> sign({
required BearerDid did,
required JwtClaims payload,
String? type = 'JWT',
}) async {
final header = JwtHeader(typ: 'JWT');
final header = JwtHeader(typ: type);
final payloadBytes = json.toBytes(payload.toJson());

return Jws.sign(did: did, payload: payloadBytes, header: header);
Expand Down
19 changes: 17 additions & 2 deletions packages/web5/test/jwt/jwt_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@ void main() {
test('should decode signed JWT', () async {
final did = await DidJwk.create();

final signedJwt =
await Jwt.sign(did: did, payload: JwtClaims(iss: did.uri));
final signedJwt = await Jwt.sign(
did: did,
payload: JwtClaims(iss: did.uri),
);

final parsedJwt = Jwt.decode(signedJwt);
expect(parsedJwt.header.kid, contains('${did.uri}#'));
expect(parsedJwt.claims.iss, equals(did.uri));
});

test('should allow for custom typ', () async {
final did = await DidJwk.create();

final signedJwt = await Jwt.sign(
did: did,
payload: JwtClaims(iss: did.uri),
type: 'custom',
);

final parsedJwt = Jwt.decode(signedJwt);
expect(parsedJwt.header.typ, equals('custom'));
});

test('should verify JWT signed by did:jwk', () async {
final did = await DidJwk.create();

Expand Down
Loading