mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-07-07 18:45:09 +00:00
Google login temporary workaround
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<button style="margin-top: 0.5em;" (click)="clearCache()" class="ui button">Clear Cache</button>
|
<button style="margin-top: 0.5em;" (click)="clearCache()" class="ui button">Clear Cache</button>
|
||||||
|
|
||||||
<h3 class="ui header">Downloads</h3>
|
<h3 *ngIf="loginAvailable" class="ui header">Downloads</h3>
|
||||||
<div class="ui form">
|
<div class="ui form">
|
||||||
<div *ngIf="loginAvailable" class="field">
|
<div *ngIf="loginAvailable" class="field">
|
||||||
<label>Google rate limit delay</label>
|
<label>Google rate limit delay</label>
|
||||||
@@ -28,7 +28,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="loginAvailable" class="field">
|
<!-- TODO: Uncomment this when switching to the OAuth2 Login system -->
|
||||||
|
<!-- <div *ngIf="loginAvailable" class="field">
|
||||||
<div class="ui button" data-tooltip="Removes rate limit delay" data-position="right center" (click)="googleLogin()">
|
<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
|
<i class="google icon"></i>Sign in with Google
|
||||||
</div>
|
</div>
|
||||||
@@ -37,7 +38,7 @@
|
|||||||
<div class="ui button" (click)="googleLogout()">
|
<div class="ui button" (click)="googleLogout()">
|
||||||
<i class="google icon"></i>Sign out
|
<i class="google icon"></i>Sign out
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> -->
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="settingsService.rateLimitDelay < 30" class="ui warning message">
|
<div *ngIf="settingsService.rateLimitDelay < 30" class="ui warning message">
|
||||||
<i class="exclamation circle icon"></i>
|
<i class="exclamation circle icon"></i>
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import { mainWindow } from '../../main'
|
|||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { readFile, writeFile } from 'jsonfile'
|
import { readFile, writeFile } from 'jsonfile'
|
||||||
import { google } from 'googleapis'
|
import { google } from 'googleapis'
|
||||||
|
import * as needle from 'needle'
|
||||||
import { authServer } from './AuthServer'
|
import { authServer } from './AuthServer'
|
||||||
import { BrowserWindow } from 'electron'
|
import { BrowserWindow } from 'electron'
|
||||||
|
import { serverURL } from '../../shared/Paths'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
|
|
||||||
@@ -24,23 +26,42 @@ export class GoogleAuth {
|
|||||||
* @returns `true` if the user is authenticated, and `false` otherwise.
|
* @returns `true` if the user is authenticated, and `false` otherwise.
|
||||||
*/
|
*/
|
||||||
async attemptToAuthenticate() {
|
async attemptToAuthenticate() {
|
||||||
if (this.hasTriedTokenFile) {
|
|
||||||
return this.hasAuthenticated
|
|
||||||
}
|
|
||||||
|
|
||||||
const token = await this.getStoredToken()
|
// TODO remove this workaround when Google's API stops being dumb
|
||||||
if (token != null) {
|
return new Promise<boolean>(resolve => {
|
||||||
// Token has been restored from a previous session
|
needle.request(
|
||||||
const oAuth2Client = new google.auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI)
|
'get',
|
||||||
oAuth2Client.setCredentials(token)
|
serverURL + `/api/data/temp`, null, (err, response) => {
|
||||||
google.options({ auth: oAuth2Client })
|
if (err) {
|
||||||
this.hasAuthenticated = true
|
resolve(false)
|
||||||
return true
|
} else {
|
||||||
} else {
|
if (!response.body.includes || (response.body as string)?.includes('<!DOCTYPE html>')) {
|
||||||
// Token doesn't exist; user has not authenticated
|
resolve(false)
|
||||||
this.hasAuthenticated = false
|
} else {
|
||||||
return false
|
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
|
||||||
|
// return true
|
||||||
|
// } else {
|
||||||
|
// // Token doesn't exist; user has not authenticated
|
||||||
|
// this.hasAuthenticated = false
|
||||||
|
// return false
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateAuthToken() {
|
async generateAuthToken() {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class GoogleLogoutHandler implements IPCInvokeHandler<'google-logout'> {
|
|||||||
*/
|
*/
|
||||||
async handler() {
|
async handler() {
|
||||||
return new Promise<undefined>(resolve => {
|
return new Promise<undefined>(resolve => {
|
||||||
googleAuth.deleteStoredToken().then(() => resolve())
|
googleAuth.deleteStoredToken().then(() => resolve(undefined))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user