An open API service indexing awesome lists of open source software.

https://github.com/fennec-framework/fennec_jwt


https://github.com/fennec-framework/fennec_jwt

dart fennec jwt

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

**fennec_jwt** is dart plugin for generate and validate jwt. it belongs to fennec framework [pub.dev](https://pub.dev/packages/fennec) but it can be used
separately.

# supported hashing algorithms:
- SHA-1

- SHA-256

- SHA-512

- MD5

# installation:

install the plugin from [pub.dev](https://pub.dev/packages/fennec_jwt)

# usage

``` dart

import 'dart:math';

import 'package:fennec_jwt/fennec_jwt.dart';

final String sharedSecret = '123456';
void main(List arguments) {
final claimSet = JwtClaim(
issuer: 'fennec_jwt',
subject: 'jwt',
audience: ['fennec_jwt@test.com'],
jwtId: generateRandomString(32),
otherClaims: {},
maxAge: const Duration(minutes: 5),
);
final token = generateJwtHS256(claimSet, sharedSecret);

print('JWT: "$token"\n');
validateJwt(token);
}

void validateJwt(String token) {
final claimSet = verifyJwtHS256Signature(token, sharedSecret);
claimSet.validate(issuer: 'fennec_jwt', audience: 'fennec_jwt@test.com');
print(claimSet.toJson());
}

String generateRandomString(int len) {
var r = Random();
return String.fromCharCodes(
List.generate(len, (index) => r.nextInt(33) + 89));
}

```

# LICENSE

[MIT](https://github.com/Fennec-Framework/fennec_jwt/blob/master/LICENSE)