Revert to OAuth authentication system

This commit is contained in:
Geomitron
2021-02-02 11:13:31 -05:00
parent 7cda6162b7
commit 911b5a51e9
2 changed files with 39 additions and 35 deletions

View File

@@ -28,40 +28,44 @@ export class GoogleAuth {
async attemptToAuthenticate() {
// TODO remove this workaround when Google's API stops being dumb
return new Promise<boolean>(resolve => {
needle.request(
'get',
serverURL + `/api/data/temp`, null, (err, response) => {
if (err) {
resolve(false)
} else {
if (!response.body.includes || (response.body as string)?.includes('<!DOCTYPE html>')) {
resolve(false)
} else {
google.options({ auth: response.body })
resolve(true)
}
}
})
})
// if (this.hasTriedTokenFile) {
// return this.hasAuthenticated
// }
// const token = await this.getStoredToken()
// if (token != null) {
// // Token has been restored from a previous session
// const oAuth2Client = new google.auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI)
// oAuth2Client.setCredentials(token)
// google.options({ auth: oAuth2Client })
// this.hasAuthenticated = true
// if (this.hasAuthenticated) {
// return true
// } else {
// // Token doesn't exist; user has not authenticated
// this.hasAuthenticated = false
// return false
// }
// return new Promise<boolean>(resolve => {
// needle.request(
// 'get',
// serverURL + `/api/data/temp`, null, (err, response) => {
// if (err) {
// resolve(false)
// } else {
// if (!response.body.includes || (response.body as string)?.includes('<!DOCTYPE html>')) {
// resolve(false)
// } else {
// google.options({ auth: response.body })
// this.hasAuthenticated = true
// resolve(true)
// }
// }
// })
// })
if (this.hasTriedTokenFile) {
return this.hasAuthenticated
}
const token = await this.getStoredToken()
if (token != null) {
// Token has been restored from a previous session
const oAuth2Client = new google.auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI)
oAuth2Client.setCredentials(token)
google.options({ auth: oAuth2Client })
this.hasAuthenticated = true
return true
} else {
// Token doesn't exist; user has not authenticated
this.hasAuthenticated = false
return false
}
}
async generateAuthToken() {