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

@@ -17,7 +17,7 @@
</div>
<button style="margin-top: 0.5em;" (click)="clearCache()" class="ui button">Clear Cache</button>
<h3 *ngIf="loginAvailable" class="ui header">Downloads</h3>
<h3 class="ui header">Downloads</h3>
<div class="ui form">
<div *ngIf="loginAvailable" class="field">
<label>Google rate limit delay</label>
@@ -29,7 +29,7 @@
</div>
</div>
<!-- TODO: Uncomment this when switching to the OAuth2 Login system -->
<!-- <div *ngIf="loginAvailable" class="field">
<div *ngIf="loginAvailable" class="field">
<div class="ui button" data-tooltip="Removes rate limit delay" data-position="right center" (click)="googleLogin()">
<i class="google icon"></i>Sign in with Google
</div>
@@ -38,7 +38,7 @@
<div class="ui button" (click)="googleLogout()">
<i class="google icon"></i>Sign out
</div>
</div> -->
</div>
</div>
<div *ngIf="settingsService.rateLimitDelay < 30" class="ui warning message">
<i class="exclamation circle icon"></i>

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() {