mirror of
https://github.com/jonasroussel/dart_jsonwebtoken.git
synced 2025-05-22 10:36:23 +08:00
v0.2.1
This commit is contained in:
@ -1,3 +1,11 @@
|
||||
## 0.2.1
|
||||
|
||||
- Formatting
|
||||
|
||||
## 0.2.0
|
||||
|
||||
- Better documentations
|
||||
|
||||
## 0.1.0
|
||||
|
||||
- First version with every based features
|
||||
|
47
README.md
47
README.md
@ -1,2 +1,47 @@
|
||||
# JsonWebToken
|
||||
[](https://pub.dev/packages/jsonwebtoken)
|
||||
[](https://pub.dev/packages/dart_jsonwebtoken)
|
||||
|
||||
A dart implementation of the famous javascript library `jsonwebtoken`.
|
||||
|
||||
## Usage
|
||||
|
||||
### Import
|
||||
```dart
|
||||
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
||||
```
|
||||
|
||||
### Sign
|
||||
|
||||
```dart
|
||||
// Create a json web token
|
||||
final jwt = JWT(
|
||||
payload: {
|
||||
'id': 123,
|
||||
'server': {
|
||||
'id': '3e4fc296',
|
||||
'loc': 'euw-2',
|
||||
}
|
||||
},
|
||||
issuer: 'https://github.com/jonasroussel/jsonwebtoken',
|
||||
);
|
||||
|
||||
// Sign it
|
||||
token = jwt.sign('secret-key');
|
||||
|
||||
print('Signed token: $token\n');
|
||||
```
|
||||
|
||||
### Verify
|
||||
|
||||
```dart
|
||||
try {
|
||||
// Verify a token
|
||||
final jwt = JWT.verify(token, 'secret-key');
|
||||
|
||||
print('Payload: ${jwt.payload}');
|
||||
} on JWTExpiredError {
|
||||
print('jwt expired');
|
||||
} on JWTError catch (ex) {
|
||||
print(ex.message); // ex: invalid signature
|
||||
}
|
||||
```
|
||||
|
@ -1,4 +1,4 @@
|
||||
import 'package:jsonwebtoken/jsonwebtoken.dart';
|
||||
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
||||
|
||||
main() {
|
||||
String token;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:jsonwebtoken/jsonwebtoken.dart';
|
||||
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
||||
|
||||
abstract class JWTAlgorithm {
|
||||
static const HS256 = HS256Algorithm();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:jsonwebtoken/jsonwebtoken.dart';
|
||||
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
|
||||
|
||||
import './utils.dart';
|
||||
|
||||
@ -39,8 +39,8 @@ class JWT {
|
||||
issuer: payload.remove('iss'),
|
||||
subject: payload.remove('sub'),
|
||||
);
|
||||
} on JWTError catch (ex) {
|
||||
throw ex;
|
||||
} on JWTError {
|
||||
rethrow;
|
||||
} catch (ex) {
|
||||
throw JWTInvalidError('jwt invalid');
|
||||
}
|
||||
@ -61,7 +61,7 @@ class JWT {
|
||||
String sign(
|
||||
String key, {
|
||||
JWTAlgorithm algorithm = JWTAlgorithm.HS256,
|
||||
Duration expiresIn = null,
|
||||
Duration expiresIn,
|
||||
bool noTimestamp = false,
|
||||
}) {
|
||||
final header = {'alg': algorithm.name, 'typ': 'JWT'};
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: jsonwebtoken
|
||||
description: A dart implementation of JSON Web Tokens.
|
||||
version: 0.1.0
|
||||
name: dart_jsonwebtoken
|
||||
description: A dart implementation of the famous javascript library 'jsonwebtoken'.
|
||||
version: 0.2.1
|
||||
repository: https://github.com/jonasroussel/jsonwebtoken
|
||||
homepage: https://github.com/jonasroussel/jsonwebtoken#readme
|
||||
|
||||
|
Reference in New Issue
Block a user