@@ -15,12 +15,12 @@ import (
1515const (
1616 tokenFilePath = ".mcpregistry_token"
1717
18- // TODO: Replace this with the official owned OAuth client ID
19- GithubClientID = "Ov23ct0x1531TPL3WJ9h"
20-
2118 // GitHub OAuth URLs
2219 GitHubDeviceCodeURL = "https://github.com/login/device/code"
2320 GitHubAccessTokenURL = "https://github.com/login/oauth/access_token"
21+
22+ // Environment variable for GitHub Client ID
23+ EnvGithubClientID = "MCP_REGISTRY_GITHUB_CLIENT_ID"
2424)
2525
2626// DeviceCodeResponse represents the response from GitHub's device code endpoint
@@ -58,6 +58,19 @@ func main() {
5858 return
5959 }
6060
61+ // Check for GitHub client ID in environment if we're going to need it for authentication
62+ if providedToken == "" && os .Getenv (EnvGithubClientID ) == "" {
63+ fmt .Printf ("Warning: Environment variable %s is not set. This is required for GitHub authentication.\n " , EnvGithubClientID )
64+ fmt .Println ("You can set it with: export " + EnvGithubClientID + "=your_github_client_id" )
65+ fmt .Println ("Or provide a token directly with the --token flag." )
66+
67+ // Only return if we'll need to do GitHub auth
68+ _ , statErr := os .Stat (tokenFilePath )
69+ if forceLogin || os .IsNotExist (statErr ) {
70+ return
71+ }
72+ }
73+
6174 var token string
6275
6376 // If a token is provided via the command line, use it
@@ -101,6 +114,11 @@ func main() {
101114}
102115
103116func performDeviceFlowLogin () error {
117+ // Check if the environment variable is set
118+ if os .Getenv (EnvGithubClientID ) == "" {
119+ return fmt .Errorf ("environment variable %s must be set for GitHub authentication" , EnvGithubClientID )
120+ }
121+
104122 // Device flow login logic using GitHub's device flow
105123 // First, request a device code
106124 deviceCode , userCode , verificationURI , err := requestDeviceCode ()
@@ -133,8 +151,13 @@ func performDeviceFlowLogin() error {
133151
134152// requestDeviceCode initiates the device authorization flow
135153func requestDeviceCode () (string , string , string , error ) {
154+ clientID := os .Getenv (EnvGithubClientID )
155+ if clientID == "" {
156+ return "" , "" , "" , fmt .Errorf ("environment variable %s is not set" , EnvGithubClientID )
157+ }
158+
136159 payload := map [string ]string {
137- "client_id" : GithubClientID ,
160+ "client_id" : clientID ,
138161 "scope" : "read:org read:user" ,
139162 }
140163
@@ -177,8 +200,13 @@ func requestDeviceCode() (string, string, string, error) {
177200
178201// pollForToken polls for access token after user completes authorization
179202func pollForToken (deviceCode string ) (string , error ) {
203+ clientID := os .Getenv (EnvGithubClientID )
204+ if clientID == "" {
205+ return "" , fmt .Errorf ("environment variable %s is not set" , EnvGithubClientID )
206+ }
207+
180208 payload := map [string ]string {
181- "client_id" : GithubClientID ,
209+ "client_id" : clientID ,
182210 "device_code" : deviceCode ,
183211 "grant_type" : "urn:ietf:params:oauth:grant-type:device_code" ,
184212 }
0 commit comments