MCPcopy Create free account
hub / github.com/Alorse/copilot-to-api / refreshCopilotToken

Method refreshCopilotToken

copilot-client.js:50–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48 }
49
50 async refreshCopilotToken() {
51 console.log('🔄 Refreshing Copilot token...');
52
53 const options = {
54 hostname: 'api.github.com',
55 port: 443,
56 path: '/copilot_internal/v2/token',
57 method: 'GET',
58 headers: {
59 'authorization': `token ${this.config.access_token}`,
60 'user-agent': 'GithubCopilot/1.155.0'
61 }
62 };
63
64 try {
65 const response = await this.makeRequest(options);
66
67 if (response.status === 200) {
68 this.copilotToken = response.data.token;
69 // Use the expires_at timestamp from the API response (subtract 60 seconds for safety margin)
70 this.tokenExpiry = (response.data.expires_at * 1000) - (60 * 1000);
71 console.log('✅ Copilot token refreshed successfully');
72 return true;
73 } else {
74 console.error('❌ Error refreshing token:', response.data);
75 return false;
76 }
77 } catch (error) {
78 console.error('❌ Network error refreshing token:', error.message);
79 return false;
80 }
81 }
82
83 async ensureValidToken() {
84 if (!this.copilotToken || !this.tokenExpiry || Date.now() > this.tokenExpiry) {

Callers 1

ensureValidTokenMethod · 0.95

Calls 1

makeRequestMethod · 0.95

Tested by

no test coverage detected