-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auth.dart
59 lines (44 loc) · 1.41 KB
/
Auth.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#library('auth');
#import('Base64.dart');
class Auth {
final String ISS = '444182523525.apps.googleusercontent.com';
final String SCOPE = 'https://www.googleapis.com/auth/tasks';
final String AUD = 'https://accounts.google.com/o/oauth2/token';
Base64 base64;
// Constructor.
Auth() {
base64 = new Base64();
}
// Build JWT from params.
String buildJWT() {
String exp = '';
String iat = '';
String header = '{"alg":"RS256","typ":"JWT"}';
StringBuffer claim = new StringBuffer();
// Body.
claim.add('{');
claim.add('"iss":"' + ISS + '",');
claim.add('"scope":"' + SCOPE + '",');
claim.add('"aud":"' + AUD + '",');
claim.add('"exp":"' + exp + '",');
claim.add('"iat":"' + iat + '"');
claim.add('}');
// Signature.
StringBuffer signature = new StringBuffer();
signature.add('{');
signature.add(this.base64.encode(header));
signature.add('.');
signature.add(this.base64.encode(claim.toString()));
signature.add('}');
print(header);
print(claim.toString());
print(signature.toString());
StringBuffer buffer = new StringBuffer();
buffer.add(this.base64.encode(header));
buffer.add('.');
buffer.add(this.base64.encode(claim.toString()));
buffer.add('.');
buffer.add(this.base64.encode(signature.toString()));
return buffer.toString();
}
}