Skip to content

Commit 3cef733

Browse files
feat: add external auth ID handling and GitHub authentication setup
1 parent b880e24 commit 3cef733

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

registry/coder-labs/modules/copilot-cli/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ module "agentapi" {
226226
ARG_ALLOW_TOOLS='${join(",", var.allow_tools)}' \
227227
ARG_DENY_TOOLS='${join(",", var.deny_tools)}' \
228228
ARG_TRUSTED_DIRECTORIES='${join(",", var.trusted_directories)}' \
229+
ARG_EXTERNAL_AUTH_ID='${var.external_auth_id}' \
229230
/tmp/start.sh
230231
EOT
231232

registry/coder-labs/modules/copilot-cli/scripts/start.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ARG_ALLOW_ALL_TOOLS=${ARG_ALLOW_ALL_TOOLS:-false}
1616
ARG_ALLOW_TOOLS=${ARG_ALLOW_TOOLS:-}
1717
ARG_DENY_TOOLS=${ARG_DENY_TOOLS:-}
1818
ARG_TRUSTED_DIRECTORIES=${ARG_TRUSTED_DIRECTORIES:-}
19+
ARG_EXTERNAL_AUTH_ID=${ARG_EXTERNAL_AUTH_ID:-github}
1920

2021
validate_copilot_installation() {
2122
if ! command_exists copilot; then
@@ -81,6 +82,31 @@ configure_copilot_model() {
8182
fi
8283
}
8384

85+
setup_github_authentication() {
86+
echo "Setting up GitHub authentication..."
87+
88+
if command_exists coder; then
89+
local github_token
90+
if github_token=$(coder external-auth access-token "${ARG_EXTERNAL_AUTH_ID}" 2>/dev/null); then
91+
if [ -n "$github_token" ] && [ "$github_token" != "null" ]; then
92+
export GITHUB_TOKEN="$github_token"
93+
export GH_TOKEN="$github_token"
94+
echo "GitHub authentication: via Coder external auth"
95+
return 0
96+
fi
97+
fi
98+
fi
99+
100+
if command_exists gh && gh auth status > /dev/null 2>&1; then
101+
echo "GitHub authentication: via GitHub CLI"
102+
return 0
103+
fi
104+
105+
echo "WARNING: No GitHub authentication found. Copilot CLI requires authentication."
106+
echo "Please ensure GitHub external auth is configured in Coder or run 'gh auth login'"
107+
return 1
108+
}
109+
84110
start_agentapi() {
85111
echo "Starting in directory: $ARG_WORKDIR"
86112
cd "$ARG_WORKDIR"
@@ -99,7 +125,7 @@ start_agentapi() {
99125
configure_copilot_model
100126

101127
echo "COPILOT_MODEL=${ARG_COPILOT_MODEL:-${COPILOT_MODEL:-not set}}"
102-
echo "GitHub authentication: via Coder external auth"
103128

129+
setup_github_authentication
104130
validate_copilot_installation
105131
start_agentapi

0 commit comments

Comments
 (0)