-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better default account stuff, epicovt support, offline mode and dry r…
…un option
- Loading branch information
1 parent
9f00228
commit f30d736
Showing
11 changed files
with
427 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
rid: [win-x64, osx-arm64, linux-x64] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 7.0.x | ||
- name: Build | ||
run: dotnet build -c Release -r ${{ matrix.rid }} | ||
- name: Publish | ||
run: dotnet publish -c Release -r ${{ matrix.rid }} --no-build | ||
- name: Upload | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: EricLauncher-${{ matrix.rid }} | ||
path: bin/Release/net7.0/${{ matrix.rid }}/publish/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http.Headers; | ||
using System.Net.Http.Json; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace EricLauncher | ||
{ | ||
class EpicAccount | ||
{ | ||
private const string EXCHANGE_API_URL = "/account/api/oauth/exchange"; | ||
private const string VERIFY_API_URL = "/account/api/oauth/verify"; | ||
|
||
public string? AccountId; | ||
public string? DisplayName; | ||
public string AccessToken; | ||
public DateTime AccessExpiry; | ||
public string RefreshToken; | ||
public DateTime RefreshExpiry; | ||
|
||
private HttpClient HTTPClient; | ||
|
||
public EpicAccount(EpicLoginResponse login) | ||
{ | ||
AccessToken = login.access_token!; | ||
RefreshToken = login.refresh_token!; | ||
AccessExpiry = login.expires_at!; | ||
RefreshExpiry = login.refresh_expires_at!; | ||
AccountId = login.account_id!; | ||
DisplayName = login.displayName; | ||
|
||
HTTPClient = new(); | ||
HTTPClient.BaseAddress = new Uri(EpicLogin.ACCOUNTS_API_BASE); | ||
HTTPClient.DefaultRequestHeaders.Accept.Clear(); | ||
HTTPClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
HTTPClient.DefaultRequestHeaders.Add("Authorization", login.token_type + " " + login.access_token); | ||
} | ||
|
||
public EpicAccount(StoredAccountInfo info) | ||
{ | ||
if (info.AccessToken == null || info.RefreshToken == null) | ||
throw new Exception("Stored account info doesn't have access or refresh token"); | ||
|
||
if (info.AccountId != null) | ||
AccountId = info.AccountId; | ||
if (info.DisplayName != null) | ||
DisplayName = info.DisplayName; | ||
AccessToken = info.AccessToken; | ||
RefreshToken = info.RefreshToken; | ||
AccessExpiry = info.AccessExpiry; | ||
RefreshExpiry = info.RefreshExpiry; | ||
|
||
HTTPClient = new(); | ||
HTTPClient.BaseAddress = new Uri(EpicLogin.ACCOUNTS_API_BASE); | ||
HTTPClient.DefaultRequestHeaders.Accept.Clear(); | ||
HTTPClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
HTTPClient.DefaultRequestHeaders.Add("Authorization", "bearer " + info.AccessToken); | ||
} | ||
|
||
public async Task<string> GetExchangeCode() | ||
{ | ||
EpicExchangeResponse? resp = await HTTPClient.GetFromJsonAsync<EpicExchangeResponse>(EXCHANGE_API_URL); | ||
return resp!.code!; | ||
} | ||
|
||
public async Task<bool> VerifyToken() | ||
{ | ||
HttpResponseMessage resp = await HTTPClient.GetAsync(VERIFY_API_URL); | ||
if (!resp.IsSuccessStatusCode) | ||
return false; | ||
EpicVerifyResponse? verify_response = await resp.Content.ReadFromJsonAsync<EpicVerifyResponse>(); | ||
// if the token is expiring soon, why bother amirite | ||
return verify_response!.expires_in > 60; | ||
} | ||
|
||
public StoredAccountInfo MakeStoredAccountInfo() | ||
{ | ||
StoredAccountInfo info = new StoredAccountInfo(); | ||
info.AccountId = AccountId; | ||
info.RefreshExpiry = RefreshExpiry; | ||
info.RefreshToken = RefreshToken; | ||
info.AccessExpiry = AccessExpiry; | ||
info.AccessToken = AccessToken; | ||
info.DisplayName = DisplayName; | ||
return info; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http.Headers; | ||
using System.Net.Http.Json; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace EricLauncher | ||
{ | ||
class EpicEcomToken | ||
{ | ||
public string? token { get; set; } | ||
} | ||
|
||
class EpicEcom | ||
{ | ||
public const string API_BASE = "https://ecommerceintegration-public-service-ecomprod02.ol.epicgames.com"; | ||
|
||
private const string OWT_API_TEMPLATE = "/ecommerceintegration/api/public/platforms/EPIC/identities/{0}/ownershipToken"; | ||
|
||
private EpicAccount Account; | ||
private HttpClient HTTPClient; | ||
|
||
public EpicEcom(EpicAccount account) | ||
{ | ||
Account = account; | ||
|
||
HTTPClient = new(); | ||
HTTPClient.BaseAddress = new Uri(API_BASE); | ||
HTTPClient.DefaultRequestHeaders.Accept.Clear(); | ||
HTTPClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
HTTPClient.DefaultRequestHeaders.Add("Authorization", "bearer " + account.AccessToken!); | ||
} | ||
|
||
public async Task<string?> GetOwnershipToken(string catalog_namespace, string catalog_item_id) | ||
{ | ||
string formatted_url = string.Format(OWT_API_TEMPLATE, Account.AccountId!); | ||
HttpResponseMessage resp = await HTTPClient.PostAsync(formatted_url, new StringContent($"nsCatalogItemId={catalog_namespace}:{catalog_item_id}", Encoding.UTF8, "application/x-www-form-urlencoded")); | ||
if (!resp.IsSuccessStatusCode) | ||
{ | ||
EpicError? error_response = await resp.Content.ReadFromJsonAsync<EpicError>(); | ||
Console.WriteLine($"Failed to fetch ownership token: '{error_response!.errorMessage}' ({error_response!.errorCode})"); | ||
return null; | ||
} | ||
EpicEcomToken? ecom_response = await resp.Content.ReadFromJsonAsync<EpicEcomToken>(); | ||
return ecom_response!.token; | ||
} | ||
} | ||
} |
Oops, something went wrong.