Last active
June 4, 2018 07:45
-
-
Save sj82516/70f15cdb6d085f631f0e77caefa76aa4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const jwt = require('jsonwebtoken'); | |
| // 剛才下載的檔案 | |
| const googleServerKey = require("./test-f9099.json") | |
| const token = jwt.sign({ | |
| "iss": googleServerKey.client_email, | |
| scope, | |
| "aud": "https://www.googleapis.com/oauth2/v4/token", | |
| "exp": Math.floor(Date.now() / 1000) + (60 * 60), | |
| "iat": Math.floor(Date.now() / 1000) | |
| }, googleServerKey.private_key, { | |
| header: { | |
| "alg": "RS256", | |
| "typ": "JWT" | |
| } | |
| }) | |
| function getAccessTokenByJWT() { | |
| let data = qs.stringify({ | |
| grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer", | |
| assertion: token, | |
| }); | |
| const headers = { | |
| 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', | |
| }; | |
| return axios.post('https://www.googleapis.com/oauth2/v4/token', data, { | |
| headers | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment