Skip to content
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

Added ability to authenticate with RiotClientUx #51

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ LeagueClientUx process. If you wish to await until a client is found, you can us

| Option | Default Value | Description |
|--------|---------------|-------------|
| name | `LeagueClientUx` | League Client name, set to RiotClientUx if you would like to authenticate with the Riot Client
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for updating the documentation!

| awaitConnection | `false` | Await until a LeagueClientUx process is found |
| pollInterval | `2500` | Duration in milliseconds between each poll. No-op if awaitConnection is false. |
| certificate | `undefined` | A plain-text self-signed certificate to authenticate to the LCU API with. This option should only be used if you're self-signing with a certificate which is not the one Riot Games provides on their developer page. League Connect will default to using Riot's own self-signed certificate for authentication. If you're of what this option does, you should probably not use it. |
Expand Down
13 changes: 11 additions & 2 deletions src/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import util from 'util'

const exec = util.promisify(cp.exec)

const DEFAULT_NAME = 'LeagueClientUx'
const DEFAULT_POLL_INTERVAL = 2500

export interface Credentials {
Expand All @@ -28,6 +29,13 @@ export interface Credentials {
}

export interface AuthenticationOptions {
/**
* League Client process name. Set to RiotClientUx if you would like to
* authenticate with the Riot Client
*
* Defaults: LeagueClientUx
*/
name?: string
/**
* Does not return before the League Client has been detected. This means the
* function stays unresolved until a League has been found.
Expand Down Expand Up @@ -91,14 +99,15 @@ export async function authenticate(options?: AuthenticationOptions): Promise<Cre
const RIOT_GAMES_CERT = await fs.promises.readFile(path.join(__dirname, '..', 'riotgames.pem'), 'utf-8')

async function tryAuthenticate() {
const name = options?.name ?? DEFAULT_NAME
const portRegex = /--app-port=([0-9]+)/
const passwordRegex = /--remoting-auth-token=([\w-_]+)/
const pidRegex = /--app-pid=([0-9]+)/

const command =
process.platform === 'win32'
? "WMIC PROCESS WHERE name='LeagueClientUx.exe' GET CommandLine"
: "ps x -o args | grep 'LeagueClientUx'"
? `WMIC PROCESS WHERE name='${name}.exe' GET CommandLine`
: `ps x -o args | grep '${name}'`

try {
const { stdout } = await exec(command)
Expand Down