-
Notifications
You must be signed in to change notification settings - Fork 16
/
generic_pass.js
83 lines (76 loc) · 1.98 KB
/
generic_pass.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const { GoogleAuth } = require('google-auth-library');
const jwt = require('jsonwebtoken');
// TODO: Define issuer ID
let issuerId = 'ISSUER_ID';
let classSuffix = 'codelab_class';
let objectSuffix = 'codelab_object';
const objectId = `${issuerId}.${objectSuffix}`;
const keyFilePath = process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/key.json';
const baseUrl = 'https://walletobjects.googleapis.com/walletobjects/v1';
const credentials = require(keyFilePath);
const httpClient = new GoogleAuth({
credentials: credentials,
scopes: 'https://www.googleapis.com/auth/wallet_object.issuer'
});
// Create a Generic pass object
let genericObject = {
'id': `${objectId}`,
'classId': `${issuerId}.${classSuffix}`,
'genericType': 'GENERIC_TYPE_UNSPECIFIED',
'hexBackgroundColor': '#4285f4',
'logo': {
'sourceUri': {
'uri': 'https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/pass_google_logo.jpg'
}
},
'cardTitle': {
'defaultValue': {
'language': 'en-US',
'value': 'Google I/O \'22'
}
},
'subheader': {
'defaultValue': {
'language': 'en-US',
'value': 'Attendee'
}
},
'header': {
'defaultValue': {
'language': 'en-US',
'value': 'Alex McJacobs'
}
},
'barcode': {
'type': 'QR_CODE',
'value': `${objectId}`
},
'heroImage': {
'sourceUri': {
'uri': 'https://storage.googleapis.com/wallet-lab-tools-codelab-artifacts-public/google-io-hero-demo-only.jpg'
}
},
'textModulesData': [
{
'header': 'POINTS',
'body': '1234',
'id': 'points'
},
{
'header': 'CONTACTS',
'body': '20',
'id': 'contacts'
}
]
}
const claims = {
iss: credentials.client_email, // `client_email` in service account file.
aud: 'google',
origins: ['http://localhost:3000'],
typ: 'savetowallet',
payload: {
genericObjects: [genericObject],
},
};
const token = jwt.sign(claims, credentials.private_key, {algorithm: 'RS256'});
console.log(token)