mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-09 05:09:39 +00:00
Revert to OAuth authentication system
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user