diff --git a/octorun/.env.template b/octorun/.env.template index 2c1f93479..a42e21c4a 100644 --- a/octorun/.env.template +++ b/octorun/.env.template @@ -1,4 +1,5 @@ OCTOKIT_CLIENT_ID= OCTOKIT_CLIENT_SECRET= +OCTOKIT_USER_AGENT= OCTORUN_USER= OCTORUN_TOKEN= \ No newline at end of file diff --git a/octorun/src/api.js b/octorun/src/api.js index b447f564e..32322ef6a 100644 --- a/octorun/src/api.js +++ b/octorun/src/api.js @@ -5,7 +5,11 @@ function ApiWrapper() { this.octokit = octokitWrapper.createOctokit(); if (!config.user || !config.token) { - throw "User and/or Token missing"; + throw "user and/or token missing"; + } + + if (!config.appName) { + throw "appName missing"; } this.octokit.authenticate({ diff --git a/octorun/src/authentication.js b/octorun/src/authentication.js index 7f7b45685..e2d082100 100644 --- a/octorun/src/authentication.js +++ b/octorun/src/authentication.js @@ -9,6 +9,14 @@ var twoFactorRegex = new RegExp("must specify two-factor authentication otp code var badCredentialsRegex = new RegExp("bad credentials", "gi"); var handleBasicAuthentication = function (username, password, onSuccess, onRequiresTwoFa, onFailure) { + if (!config.clientId || !config.clientSecret) { + throw "clientId and/or clientSecret missing"; + } + + if (!config.appName) { + throw "appName missing"; + } + var octokit = octokitWrapper.createOctokit(); octokit.authenticate({ @@ -44,6 +52,14 @@ var handleBasicAuthentication = function (username, password, onSuccess, onRequi } var handleTwoFactorAuthentication = function (username, password, twoFactor, onSuccess, onFailure) { + if (!config.clientId || !config.clientSecret) { + throw "clientId and/or clientSecret missing"; + } + + if (!config.appName) { + throw "appName missing"; + } + var octokit = octokitWrapper.createOctokit(); octokit.authenticate({ @@ -54,11 +70,11 @@ var handleTwoFactorAuthentication = function (username, password, twoFactor, onS octokit.authorization.create({ scopes: scopes, - note: config.appName, client_id: config.clientId, client_secret: config.clientSecret, headers: { - "X-GitHub-OTP": twoFactor + "X-GitHub-OTP": twoFactor, + "user-agent": config.appName } }, function (err, res) { if (err) { diff --git a/octorun/src/bin/app-login.js b/octorun/src/bin/app-login.js index 0e450bfd4..eec473f4d 100644 --- a/octorun/src/bin/app-login.js +++ b/octorun/src/bin/app-login.js @@ -31,7 +31,13 @@ if (commander.twoFactor) { var twoFactor = readlineSync.question('Two Factor: '); - handleTwoFactorAuthentication(username, password, twoFactor); + try { + handleTwoFactorAuthentication(username, password, twoFactor); + } + catch (error) { + output.error(error); + process.exit(); + } } else { var data = ''; @@ -49,7 +55,13 @@ if (commander.twoFactor) { .split(/\r?\n/) .filter(function (item) { return item; }); - handleTwoFactorAuthentication(items[0], items[1], items[2]); + try { + handleTwoFactorAuthentication(items[0], items[1], items[2]); + } + catch (error) { + output.error(error); + process.exit(); + } }); } } @@ -76,7 +88,13 @@ else { hideEchoBack: true }); - handleBasicAuthentication(username, password); + try { + handleBasicAuthentication(username, password); + } + catch (error) { + output.error(error); + process.exit(); + } } else { var data = ''; @@ -94,7 +112,13 @@ else { .split(/\r?\n/) .filter(function (item) { return item; }); - handleBasicAuthentication(items[0], items[1]); + try { + handleBasicAuthentication(items[0], items[1]); + } + catch (error) { + output.error(error); + process.exit(); + } }); } } \ No newline at end of file diff --git a/octorun/src/configuration.js b/octorun/src/configuration.js index ba5ad4447..f9462acde 100644 --- a/octorun/src/configuration.js +++ b/octorun/src/configuration.js @@ -2,7 +2,7 @@ require("dotenv").config({silent: true}); var clientId = process.env.OCTOKIT_CLIENT_ID; var clientSecret = process.env.OCTOKIT_CLIENT_SECRET; -var appName = process.env.OCTORUN_APP_NAME | "octorun"; +var appName = process.env.OCTOKIT_USER_AGENT; var user = process.env.OCTORUN_USER; var token = process.env.OCTORUN_TOKEN; diff --git a/src/GitHub.Api/Application/ApplicationInfo.cs b/src/GitHub.Api/Application/ApplicationInfo.cs index 83b2387cd..4b766f75a 100644 --- a/src/GitHub.Api/Application/ApplicationInfo.cs +++ b/src/GitHub.Api/Application/ApplicationInfo.cs @@ -10,7 +10,7 @@ static partial class ApplicationInfo public const string ApplicationName = "GitHubUnity"; public const string ApplicationProvider = "GitHub"; #endif - public const string ApplicationSafeName = "unity-internal-test"; + public const string ApplicationSafeName = "GitHubUnity"; public const string ApplicationDescription = "GitHub for Unity"; internal static string ClientId { get; private set; } = ""; diff --git a/src/GitHub.Api/Tasks/OctorunTask.cs b/src/GitHub.Api/Tasks/OctorunTask.cs index b435b1996..982dedfae 100644 --- a/src/GitHub.Api/Tasks/OctorunTask.cs +++ b/src/GitHub.Api/Tasks/OctorunTask.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Reflection; using System.Threading; using GitHub.Logging; @@ -57,6 +58,7 @@ class OctorunTask : ProcessTask private readonly string userToken; private readonly NPath pathToNodeJs; + private readonly NPath pathToOctorunJs; private readonly string arguments; public OctorunTask(CancellationToken token, NPath pathToNodeJs, NPath pathToOctorunJs, string arguments, @@ -72,6 +74,7 @@ public OctorunTask(CancellationToken token, NPath pathToNodeJs, NPath pathToOcto this.user = user; this.userToken = userToken; this.pathToNodeJs = pathToNodeJs; + this.pathToOctorunJs = pathToOctorunJs; this.arguments = $"{pathToOctorunJs} {arguments}"; } @@ -79,6 +82,10 @@ public override void Configure(ProcessStartInfo psi) { base.Configure(psi); + psi.WorkingDirectory = pathToOctorunJs.Parent.Parent.Parent; + + psi.EnvironmentVariables.Add("OCTOKIT_USER_AGENT", $"{ApplicationInfo.ApplicationSafeName}/{ApplicationInfo.Version}"); + if (clientId != null) { psi.EnvironmentVariables.Add("OCTOKIT_CLIENT_ID", clientId);