Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ new CopilotClient(CopilotClientOptions? options = null)
- `Cwd` - Working directory for the CLI process
- `Environment` - Environment variables to pass to the CLI process
- `Logger` - `ILogger` instance for SDK logging
- `GithubToken` - GitHub token for authentication. When provided, takes priority over other auth methods.
- `UseLoggedInUser` - Whether to use logged-in user for authentication (default: true, but false when `GithubToken` is provided). Cannot be used with `CliUrl`.
- `GitHubToken` - GitHub token for authentication. When provided, takes priority over other auth methods.
- `UseLoggedInUser` - Whether to use logged-in user for authentication (default: true, but false when `GitHubToken` is provided). Cannot be used with `CliUrl`.

#### Methods

Expand Down
14 changes: 7 additions & 7 deletions dotnet/src/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public CopilotClient(CopilotClientOptions? options = null)
}

// Validate auth options with external server
if (!string.IsNullOrEmpty(_options.CliUrl) && (!string.IsNullOrEmpty(_options.GithubToken) || _options.UseLoggedInUser != null))
if (!string.IsNullOrEmpty(_options.CliUrl) && (!string.IsNullOrEmpty(_options.GitHubToken) || _options.UseLoggedInUser != null))
{
throw new ArgumentException("GithubToken and UseLoggedInUser cannot be used with CliUrl (external server manages its own auth)");
throw new ArgumentException("GitHubToken and UseLoggedInUser cannot be used with CliUrl (external server manages its own auth)");
}

_logger = _options.Logger ?? NullLogger.Instance;
Expand Down Expand Up @@ -944,13 +944,13 @@ private async Task VerifyProtocolVersionAsync(Connection connection, Cancellatio
}

// Add auth-related flags
if (!string.IsNullOrEmpty(options.GithubToken))
if (!string.IsNullOrEmpty(options.GitHubToken))
{
args.AddRange(["--auth-token-env", "COPILOT_SDK_AUTH_TOKEN"]);
}

// Default UseLoggedInUser to false when GithubToken is provided
var useLoggedInUser = options.UseLoggedInUser ?? string.IsNullOrEmpty(options.GithubToken);
// Default UseLoggedInUser to false when GitHubToken is provided
var useLoggedInUser = options.UseLoggedInUser ?? string.IsNullOrEmpty(options.GitHubToken);
if (!useLoggedInUser)
{
args.Add("--no-auto-login");
Expand Down Expand Up @@ -982,9 +982,9 @@ private async Task VerifyProtocolVersionAsync(Connection connection, Cancellatio
startInfo.Environment.Remove("NODE_DEBUG");

// Set auth token in environment if provided
if (!string.IsNullOrEmpty(options.GithubToken))
if (!string.IsNullOrEmpty(options.GitHubToken))
{
startInfo.Environment["COPILOT_SDK_AUTH_TOKEN"] = options.GithubToken;
startInfo.Environment["COPILOT_SDK_AUTH_TOKEN"] = options.GitHubToken;
}

var cliProcess = new Process { StartInfo = startInfo };
Expand Down
18 changes: 14 additions & 4 deletions dotnet/src/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected CopilotClientOptions(CopilotClientOptions? other)
CliUrl = other.CliUrl;
Cwd = other.Cwd;
Environment = other.Environment;
GithubToken = other.GithubToken;
GitHubToken = other.GitHubToken;
Logger = other.Logger;
LogLevel = other.LogLevel;
Port = other.Port;
Expand Down Expand Up @@ -72,13 +72,23 @@ protected CopilotClientOptions(CopilotClientOptions? other)
/// When provided, the token is passed to the CLI server via environment variable.
/// This takes priority over other authentication methods.
/// </summary>
public string? GithubToken { get; set; }
public string? GitHubToken { get; set; }

/// <summary>
/// Obsolete. Use <see cref="GitHubToken"/> instead.
/// </summary>
[Obsolete("Use GitHubToken instead.", error: false)]
public string? GithubToken
{
get => GitHubToken;
set => GitHubToken = value;
}

/// <summary>
/// Whether to use the logged-in user for authentication.
/// When true, the CLI server will attempt to use stored OAuth tokens or gh CLI auth.
/// When false, only explicit tokens (GithubToken or environment variables) are used.
/// Default: true (but defaults to false when GithubToken is provided).
/// When false, only explicit tokens (GitHubToken or environment variables) are used.
/// Default: true (but defaults to false when GitHubToken is provided).
/// </summary>
public bool? UseLoggedInUser { get; set; }

Expand Down
14 changes: 7 additions & 7 deletions dotnet/test/ClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ public async Task Should_List_Models_When_Authenticated()
}

[Fact]
public void Should_Accept_GithubToken_Option()
public void Should_Accept_GitHubToken_Option()
{
var options = new CopilotClientOptions
{
GithubToken = "gho_test_token"
GitHubToken = "gho_test_token"
};

Assert.Equal("gho_test_token", options.GithubToken);
Assert.Equal("gho_test_token", options.GitHubToken);
}

[Fact]
Expand All @@ -179,26 +179,26 @@ public void Should_Allow_Explicit_UseLoggedInUser_False()
}

[Fact]
public void Should_Allow_Explicit_UseLoggedInUser_True_With_GithubToken()
public void Should_Allow_Explicit_UseLoggedInUser_True_With_GitHubToken()
{
var options = new CopilotClientOptions
{
GithubToken = "gho_test_token",
GitHubToken = "gho_test_token",
UseLoggedInUser = true
};

Assert.True(options.UseLoggedInUser);
}

[Fact]
public void Should_Throw_When_GithubToken_Used_With_CliUrl()
public void Should_Throw_When_GitHubToken_Used_With_CliUrl()
{
Assert.Throws<ArgumentException>(() =>
{
_ = new CopilotClient(new CopilotClientOptions
{
CliUrl = "localhost:8080",
GithubToken = "gho_test_token"
GitHubToken = "gho_test_token"
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions dotnet/test/CloneTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void CopilotClientOptions_Clone_CopiesAllProperties()
AutoStart = false,
AutoRestart = false,
Environment = new Dictionary<string, string> { ["KEY"] = "value" },
GithubToken = "ghp_test",
GitHubToken = "ghp_test",
UseLoggedInUser = false,
};

Expand All @@ -40,7 +40,7 @@ public void CopilotClientOptions_Clone_CopiesAllProperties()
Assert.Equal(original.AutoStart, clone.AutoStart);
Assert.Equal(original.AutoRestart, clone.AutoRestart);
Assert.Equal(original.Environment, clone.Environment);
Assert.Equal(original.GithubToken, clone.GithubToken);
Assert.Equal(original.GitHubToken, clone.GitHubToken);
Assert.Equal(original.UseLoggedInUser, clone.UseLoggedInUser);
}

Expand Down
2 changes: 1 addition & 1 deletion dotnet/test/Harness/E2ETestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public IReadOnlyDictionary<string, string> GetEnvironment()
Cwd = WorkDir,
CliPath = GetCliPath(_repoRoot),
Environment = GetEnvironment(),
GithubToken = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI")) ? "fake-token-for-e2e-tests" : null,
GitHubToken = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI")) ? "fake-token-for-e2e-tests" : null,
});

public async ValueTask DisposeAsync()
Expand Down
4 changes: 2 additions & 2 deletions go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ Event types: `SessionLifecycleCreated`, `SessionLifecycleDeleted`, `SessionLifec
- `AutoStart` (\*bool): Auto-start server on first use (default: true). Use `Bool(false)` to disable.
- `AutoRestart` (\*bool): Auto-restart on crash (default: true). Use `Bool(false)` to disable.
- `Env` ([]string): Environment variables for CLI process (default: inherits from current process)
- `GithubToken` (string): GitHub token for authentication. When provided, takes priority over other auth methods.
- `UseLoggedInUser` (\*bool): Whether to use logged-in user for authentication (default: true, but false when `GithubToken` is provided). Cannot be used with `CLIUrl`.
- `GitHubToken` (string): GitHub token for authentication. When provided, takes priority over other auth methods.
- `UseLoggedInUser` (\*bool): Whether to use logged-in user for authentication (default: true, but false when `GitHubToken` is provided). Cannot be used with `CLIUrl`.

**SessionConfig:**

Expand Down
18 changes: 9 additions & 9 deletions go/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func NewClient(options *ClientOptions) *Client {
}

// Validate auth options with external server
if options.CLIUrl != "" && (options.GithubToken != "" || options.UseLoggedInUser != nil) {
panic("GithubToken and UseLoggedInUser cannot be used with CLIUrl (external server manages its own auth)")
if options.CLIUrl != "" && (options.GitHubToken != "" || options.UseLoggedInUser != nil) {
panic("GitHubToken and UseLoggedInUser cannot be used with CLIUrl (external server manages its own auth)")
}

// Parse CLIUrl if provided
Expand Down Expand Up @@ -177,8 +177,8 @@ func NewClient(options *ClientOptions) *Client {
if options.AutoRestart != nil {
client.autoRestart = *options.AutoRestart
}
if options.GithubToken != "" {
opts.GithubToken = options.GithubToken
if options.GitHubToken != "" {
opts.GitHubToken = options.GitHubToken
}
if options.UseLoggedInUser != nil {
opts.UseLoggedInUser = options.UseLoggedInUser
Expand Down Expand Up @@ -1040,14 +1040,14 @@ func (c *Client) startCLIServer(ctx context.Context) error {
}

// Add auth-related flags
if c.options.GithubToken != "" {
if c.options.GitHubToken != "" {
args = append(args, "--auth-token-env", "COPILOT_SDK_AUTH_TOKEN")
}
// Default useLoggedInUser to false when GithubToken is provided
// Default useLoggedInUser to false when GitHubToken is provided
useLoggedInUser := true
if c.options.UseLoggedInUser != nil {
useLoggedInUser = *c.options.UseLoggedInUser
} else if c.options.GithubToken != "" {
} else if c.options.GitHubToken != "" {
useLoggedInUser = false
}
if !useLoggedInUser {
Expand All @@ -1074,8 +1074,8 @@ func (c *Client) startCLIServer(ctx context.Context) error {

// Add auth token if needed.
c.process.Env = c.options.Env
if c.options.GithubToken != "" {
c.process.Env = append(c.process.Env, "COPILOT_SDK_AUTH_TOKEN="+c.options.GithubToken)
if c.options.GitHubToken != "" {
c.process.Env = append(c.process.Env, "COPILOT_SDK_AUTH_TOKEN="+c.options.GitHubToken)
}

if c.useStdio {
Expand Down
22 changes: 11 additions & 11 deletions go/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,17 @@ func TestClient_URLParsing(t *testing.T) {
}

func TestClient_AuthOptions(t *testing.T) {
t.Run("should accept GithubToken option", func(t *testing.T) {
t.Run("should accept GitHubToken option", func(t *testing.T) {
client := NewClient(&ClientOptions{
GithubToken: "gho_test_token",
GitHubToken: "gho_test_token",
})

if client.options.GithubToken != "gho_test_token" {
t.Errorf("Expected GithubToken to be 'gho_test_token', got %q", client.options.GithubToken)
if client.options.GitHubToken != "gho_test_token" {
t.Errorf("Expected GitHubToken to be 'gho_test_token', got %q", client.options.GitHubToken)
}
})

t.Run("should default UseLoggedInUser to nil when no GithubToken", func(t *testing.T) {
t.Run("should default UseLoggedInUser to nil when no GitHubToken", func(t *testing.T) {
client := NewClient(&ClientOptions{})

if client.options.UseLoggedInUser != nil {
Expand All @@ -283,9 +283,9 @@ func TestClient_AuthOptions(t *testing.T) {
}
})

t.Run("should allow explicit UseLoggedInUser true with GithubToken", func(t *testing.T) {
t.Run("should allow explicit UseLoggedInUser true with GitHubToken", func(t *testing.T) {
client := NewClient(&ClientOptions{
GithubToken: "gho_test_token",
GitHubToken: "gho_test_token",
UseLoggedInUser: Bool(true),
})

Expand All @@ -294,12 +294,12 @@ func TestClient_AuthOptions(t *testing.T) {
}
})

t.Run("should throw error when GithubToken is used with CLIUrl", func(t *testing.T) {
t.Run("should throw error when GitHubToken is used with CLIUrl", func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("Expected panic for auth options with CLIUrl")
} else {
matched, _ := regexp.MatchString("GithubToken and UseLoggedInUser cannot be used with CLIUrl", r.(string))
matched, _ := regexp.MatchString("GitHubToken and UseLoggedInUser cannot be used with CLIUrl", r.(string))
if !matched {
t.Errorf("Expected panic message about auth options, got: %v", r)
}
Expand All @@ -308,7 +308,7 @@ func TestClient_AuthOptions(t *testing.T) {

NewClient(&ClientOptions{
CLIUrl: "localhost:8080",
GithubToken: "gho_test_token",
GitHubToken: "gho_test_token",
})
})

Expand All @@ -317,7 +317,7 @@ func TestClient_AuthOptions(t *testing.T) {
if r := recover(); r == nil {
t.Error("Expected panic for auth options with CLIUrl")
} else {
matched, _ := regexp.MatchString("GithubToken and UseLoggedInUser cannot be used with CLIUrl", r.(string))
matched, _ := regexp.MatchString("GitHubToken and UseLoggedInUser cannot be used with CLIUrl", r.(string))
if !matched {
t.Errorf("Expected panic message about auth options, got: %v", r)
}
Expand Down
2 changes: 1 addition & 1 deletion go/internal/e2e/testharness/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (c *TestContext) NewClient() *copilot.Client {

// Use fake token in CI to allow cached responses without real auth
if os.Getenv("CI") == "true" {
options.GithubToken = "fake-token-for-e2e-tests"
options.GitHubToken = "fake-token-for-e2e-tests"
}

return copilot.NewClient(options)
Expand Down
8 changes: 4 additions & 4 deletions go/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ type ClientOptions struct {
// If Env contains duplicate environment keys, only the last value in the
// slice for each duplicate key is used.
Env []string
// GithubToken is the GitHub token to use for authentication.
// GitHubToken is the GitHub token to use for authentication.
// When provided, the token is passed to the CLI server via environment variable.
// This takes priority over other authentication methods.
GithubToken string
GitHubToken string
// UseLoggedInUser controls whether to use the logged-in user for authentication.
// When true, the CLI server will attempt to use stored OAuth tokens or gh CLI auth.
// When false, only explicit tokens (GithubToken or environment variables) are used.
// Default: true (but defaults to false when GithubToken is provided).
// When false, only explicit tokens (GitHubToken or environment variables) are used.
// Default: true (but defaults to false when GitHubToken is provided).
// Use Bool(false) to explicitly disable.
UseLoggedInUser *bool
}
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/auth/gh-app/csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
using var client = new CopilotClient(new CopilotClientOptions
{
CliPath = Environment.GetEnvironmentVariable("COPILOT_CLI_PATH"),
GithubToken = accessToken,
GitHubToken = accessToken,
});

await client.StartAsync();
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/auth/gh-app/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func main() {
}

client := copilot.NewClient(&copilot.ClientOptions{
GithubToken: token,
GitHubToken: token,
})

ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/bundling/fully-bundled/csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using var client = new CopilotClient(new CopilotClientOptions
{
CliPath = Environment.GetEnvironmentVariable("COPILOT_CLI_PATH"),
GithubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN"),
GitHubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN"),
});

await client.StartAsync();
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/bundling/fully-bundled/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func main() {
// Go SDK auto-reads COPILOT_CLI_PATH from env
client := copilot.NewClient(&copilot.ClientOptions{
GithubToken: os.Getenv("GITHUB_TOKEN"),
GitHubToken: os.Getenv("GITHUB_TOKEN"),
})

ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/callbacks/hooks/csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using var client = new CopilotClient(new CopilotClientOptions
{
CliPath = Environment.GetEnvironmentVariable("COPILOT_CLI_PATH"),
GithubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN"),
GitHubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN"),
});

await client.StartAsync();
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/callbacks/hooks/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
}

client := copilot.NewClient(&copilot.ClientOptions{
GithubToken: os.Getenv("GITHUB_TOKEN"),
GitHubToken: os.Getenv("GITHUB_TOKEN"),
})

ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/callbacks/permissions/csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using var client = new CopilotClient(new CopilotClientOptions
{
CliPath = Environment.GetEnvironmentVariable("COPILOT_CLI_PATH"),
GithubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN"),
GitHubToken = Environment.GetEnvironmentVariable("GITHUB_TOKEN"),
});

await client.StartAsync();
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/callbacks/permissions/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
)

client := copilot.NewClient(&copilot.ClientOptions{
GithubToken: os.Getenv("GITHUB_TOKEN"),
GitHubToken: os.Getenv("GITHUB_TOKEN"),
})

ctx := context.Background()
Expand Down
Loading
Loading