Skip to content

Commit

Permalink
feat: support wyvern as auth source
Browse files Browse the repository at this point in the history
  • Loading branch information
imLinguin committed Aug 18, 2024
1 parent 0d49295 commit 438bac3
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 2 deletions.
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ rustls-pemfile = "2.1.1"
async_zip = { version = "0.0.17", features = ["tokio", "deflate"] }
base64 = "0.22.0"
serde_ini = "0.2.0"
toml = "0.8.19"

[build-dependencies]
protobuf-codegen = "3.4.0"
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ You need to obtain `access_token`, `refresh_token` and `user_id` either manually

#### Via [Heroic Games Launcher](https://github.com/Heroic-Games-Launcher/HeroicGamesLauncher)

Log in to GOG within the launcher.
Log in to GOG within the launcher.
Use `--from-heroic` for automatic import.

#### Via [Lutris](https://github.com/lutris/lutris)

Log in to Lutris's GOG source.
Log in to Lutris's GOG source.
Use `--from-lutris` for automatic import.

### Via [wyvern](https://github.com/nicohman/wyvern) (CLI)

Log in to GOG in wyvern
Use `--from-wyvern` for automatic import.


#### Via [gogdl](https://github.com/Heroic-Games-Launcher/heroic-gogdl) (CLI)

Expand Down Expand Up @@ -99,6 +107,11 @@ Or Lutris
comet --from-lutris --username <USERNAME>
```

Or wyvern
```
comet --from-wyvern --username <USERNAME>
```

Or use the shortcut script provided for non-Steam shortcuts. See the [Steam Deck Usage Guide](docs/steamdeck/USAGE.md).

## Contributing
Expand Down
10 changes: 10 additions & 0 deletions src/import_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use crate::constants;
mod heroic;
#[cfg(target_os = "linux")]
mod lutris;
#[cfg(target_os = "linux")]
mod wyvern;

pub fn handle_credentials_import(args: &crate::Args) -> (String, String, String) {
if args.heroic {
Expand Down Expand Up @@ -58,6 +60,14 @@ pub fn handle_credentials_import(args: &crate::Args) -> (String, String, String)
return (access_token, refresh_token, galaxy_user_id);
}

#[cfg(target_os = "linux")]
if args.wyvern {
let config = wyvern::load_tokens();
let token = config.token;

return token.dissolve();
}

let access_token = args.access_token.clone().expect("Access token is required");
let refresh_token = args
.refresh_token
Expand Down
40 changes: 40 additions & 0 deletions src/import_parsers/wyvern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use derive_getters::Dissolve;
use serde::Deserialize;
use std::env;
use std::fs::read_to_string;
use std::path;

#[derive(Deserialize, Dissolve)]
pub struct WyvernTokenData {
pub access_token: String,
pub refresh_token: String,
pub user_id: String,
}

#[derive(Deserialize)]
pub struct WyvernConfig {
pub token: WyvernTokenData,
}

fn get_config_path() -> Option<path::PathBuf> {
let home_dir = env::var("HOME").unwrap();
let home_dir = path::Path::new(&home_dir);

let config_path: path::PathBuf = env::var("XDG_CONFIG_HOME")
.unwrap_or_else(|_e| home_dir.join(".config").to_str().unwrap().to_string())
.into();

let wyvern_config_path = config_path.join("wyvern/wyvern.toml");

if wyvern_config_path.exists() {
Some(wyvern_config_path)
} else {
None
}
}

pub fn load_tokens() -> WyvernConfig {
let config_path = get_config_path().expect("Wyvern toml doesn't exist");
let data = read_to_string(config_path).expect("Failed to read wyvern.toml");
toml::from_str(&data).expect("Failed to parse wyvern config")
}
9 changes: 9 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ struct Args {
#[cfg(target_os = "linux")]
lutris: bool,

#[arg(
long = "from-wyvern",
help = "Load tokens from wyvern",
global = true,
group = "import"
)]
#[cfg(target_os = "linux")]
wyvern: bool,

#[arg(
short,
long,
Expand Down

0 comments on commit 438bac3

Please sign in to comment.