MCPcopy Create free account
hub / github.com/Maccoder3/MAC-MD / authorize

Method authorize

lib/gdrive.js:18–40  ·  view source on GitHub ↗
(credentials)

Source from the content-addressed store, hash-verified

16 }
17
18 async authorize(credentials) {
19 let token
20 const { client_secret, client_id } = credentials
21 const oAuth2Client = new google.auth.OAuth2(
22 client_id,
23 client_secret,
24 `http://localhost:${port}`
25 )
26 try {
27 token = JSON.parse(await fs.readFile(TOKEN_PATH))
28 } catch (e) {
29 const authUrl = oAuth2Client.generateAuthUrl({
30 access_type: 'offline',
31 scope: SCOPES,
32 })
33 this.emit('auth', authUrl)
34 let code = await promisify(this.once).bind(this)('token')
35 token = await oAuth2Client.getToken(code)
36 await fs.writeFile(TOKEN_PATH, JSON.stringify(token))
37 } finally {
38 await oAuth2Client.setCredentials(token)
39 }
40 }
41
42 token(code) {
43 this.emit('token', code)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected