-
-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[General] Beta-Feature: GOG implementation #872
Changes from 1 commit
d9177fa
3586733
a690bcc
dc1fbb0
ee0bdd6
1c225d3
df1bf00
8701177
24f6803
cdfcc75
e19b473
45cf279
eda57b1
da125a8
e1d66ec
c9c8e9c
16c6c3f
69253f6
c69b558
9639af7
ce22792
c3b9dc5
5479aae
527b03f
e1b7c2a
67a36e0
6d40928
acf593a
a54bb9c
98d9ea2
ae304cd
a40d27d
5a92f80
0f0bd05
50a3bfb
5d72a38
cc5840e
e72ec0e
f8e49fe
c214065
c84bb04
cdf416f
977097d
5d70d75
3a76ece
0dc649b
108472d
8db0cff
d11a6c8
c2d44f6
22edb9a
ec7ccea
04cf669
6789888
1db4088
209490d
65af599
4e5f347
38daf84
a5a5420
e88b8e0
4361f59
1cd11b1
f1cbab0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,18 +75,6 @@ export class GOGLibrary { | |
} | ||
} | ||
} | ||
const movies = await axios | ||
.get( | ||
'https://embed.gog.com/account/getFilteredProducts?mediaType=2&totalPages=1&sortBy=title', | ||
{ headers: headers } | ||
) | ||
.catch((e: AxiosError) => { | ||
logError( | ||
['There was an error getting movies library data', e.message], | ||
LogPrefix.Gog | ||
) | ||
return null | ||
}) | ||
|
||
if (games) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe the something like const games = await axios
.get(
'https://embed.gog.com/account/getFilteredProducts?mediaType=1&sortBy=title',
{ headers }
)
.catch((e: AxiosError) => {
logError(
['There was an error getting games library data', e.message],
LogPrefix.Gog
)
return null
This conversation was marked as resolved by flavioislima
Show conversation
})
if (!games) {
logError('There was an error Loading games library', LogPrefix.Gog)
return
}
if (games?.data?....) {
...
}
const gamesObjects: gameInfo[] = []
.... just a suggestion though, I think it's easier to reason when we can remove nesting |
||
const gamesObjects: GameInfo[] = [] | ||
|
@@ -125,10 +113,8 @@ export class GOGLibrary { | |
libraryStore.set('totalGames', games.data.totalProducts) | ||
libraryStore.set('totalMovies', games.data.moviesCount) | ||
logInfo('Saved games data', LogPrefix.Gog) | ||
} | ||
if (movies) { | ||
libraryStore.set('movies', movies.data.products) | ||
logInfo('Saved movies data', LogPrefix.Gog) | ||
} else { | ||
logError('There was an error Loading games library', LogPrefix.Gog) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,24 @@ | ||
import axios from 'axios' | ||
import Store from 'electron-store' | ||
import { BrowserWindow } from 'electron' | ||
import { logError, logInfo, LogPrefix } from '../logger/logger' | ||
import { gogLoginUrl } from '../constants' | ||
import { GOGLoginData } from '../types' | ||
|
||
const configStore = new Store({ | ||
cwd: 'gog_store' | ||
}) | ||
|
||
const gogEmbedRegExp = new RegExp('https://embed.gog.com/on_login_success?') | ||
const gogAuthenticateUrl = | ||
'https://auth.gog.com/token?client_id=46899977096215655&client_secret=9d85c43b1482497dbbce61f6e4aa173a433796eeae2ca8c5f6129f2dc4de46d9&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fembed.gog.com%2Fon_login_success%3Forigin%3Dclient&code=' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it ok that there's client_id and secret hardcoded like this? maybe it's needed but it looks suspicious to me, just checking (maybe this is the only way) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is GOG Galaxy's client_id nothing to worry about |
||
const gogRefreshTokenUrl = | ||
'https://auth.gog.com/token?client_id=46899977096215655&client_secret=9d85c43b1482497dbbce61f6e4aa173a433796eeae2ca8c5f6129f2dc4de46d9&grant_type=refresh_token' | ||
|
||
export class GOGUser { | ||
// This is executed below in edge error cases most likely won't run ever | ||
public static async handleGOGLogin() { | ||
const popupWindow = new BrowserWindow({ | ||
width: 450, | ||
height: 700, | ||
title: 'GOG' | ||
}) | ||
popupWindow.loadURL(gogLoginUrl) | ||
popupWindow.once('ready-to-show', popupWindow.show) | ||
|
||
popupWindow.webContents.on('did-finish-load', () => { | ||
const pageUrl = popupWindow.webContents.getURL() | ||
if (pageUrl.match(gogEmbedRegExp)) { | ||
const parsedURL = new URL(pageUrl) | ||
const code = parsedURL.searchParams.get('code') | ||
this.login(code) | ||
popupWindow.close() | ||
} | ||
}) | ||
} | ||
|
||
static async login(code: string) { | ||
logInfo('Logging using GOG credentials', LogPrefix.Gog) | ||
|
||
// Gets token from GOG basaed on authorization code | ||
const response = await axios | ||
.get( | ||
`https://auth.gog.com/token?client_id=46899977096215655&client_secret=9d85c43b1482497dbbce61f6e4aa173a433796eeae2ca8c5f6129f2dc4de46d9&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fembed.gog.com%2Fon_login_success%3Forigin%3Dclient&code=${code}` | ||
) | ||
.get(gogAuthenticateUrl + code) | ||
.catch((error) => { | ||
// Handle fetching error | ||
logError(['Failed to get access_token', `${error}`], LogPrefix.Gog) | ||
|
@@ -57,7 +33,7 @@ export class GOGUser { | |
data.loginTime = Date.now() | ||
configStore.set('credentials', data) | ||
logInfo('Login Successful', LogPrefix.Gog) | ||
this.getUserDetails() | ||
await this.getUserDetails() | ||
return { status: 'done' } | ||
} | ||
|
||
|
@@ -96,7 +72,6 @@ export class GOGUser { | |
'Error with refreshing token, reauth required', | ||
LogPrefix.Gog | ||
) | ||
this.handleGOGLogin() | ||
return null | ||
}) | ||
|
||
|
@@ -110,7 +85,6 @@ export class GOGUser { | |
logInfo('Token refreshed successfully', LogPrefix.Gog) | ||
} else { | ||
logError('No credentials, auth required', LogPrefix.Gog) | ||
await this.handleGOGLogin() | ||
} | ||
} | ||
|
||
|
@@ -124,10 +98,9 @@ export class GOGUser { | |
} | ||
public static logout() { | ||
const libraryStore = new Store({ cwd: 'gog_store', name: 'library' }) | ||
configStore.delete('credentials') | ||
configStore.delete('userData') | ||
libraryStore.delete('games') | ||
libraryStore.delete('movies') | ||
configStore.clear() | ||
libraryStore.clear() | ||
logInfo('Logging user out', LogPrefix.Gog) | ||
} | ||
|
||
public static isLoggedIn() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can use the isWindows isMac and isLinux from
constants
?like: