File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -198,12 +198,29 @@ async function fromKeytar(query) {
198198 log ( `reading service "atom-github" and account "${ githubHost } "` ) ;
199199 const githubPassword = await strategy . getPassword ( 'atom-github' , githubHost ) ;
200200 if ( githubPassword !== UNAUTHENTICATED ) {
201- if ( ! query . username ) {
202- // TODO find username from GitHub API
201+ try {
202+ if ( ! query . username ) {
203+ const apiUrl = githubHost === 'https://api.github.com' ? `${ githubHost } /graphql` : `${ githubHost } /api/v3/graphql` ;
204+ const response = await fetch ( apiUrl , {
205+ method : 'POST' ,
206+ headers : {
207+ 'content-type' : 'application/json' ,
208+ 'Authorization' : `bearer ${ githubPassword } ` ,
209+ 'Accept' : 'application/vnd.github.graphql-profiling+json' ,
210+ } ,
211+ body : JSON . stringify ( {
212+ query : 'query { viewer { login } }' ,
213+ } ) ,
214+ } ) ;
215+
216+ query . username = response . json ( ) . data . viewer . login ;
217+ }
218+ } catch ( e ) {
219+ log ( `unable to acquire username from token: ${ e . stack } ` ) ;
203220 throw new Error ( 'token found in keychain, but no username' ) ;
204- } else {
205- password = githubPassword ;
206221 }
222+
223+ password = githubPassword ;
207224 }
208225
209226 if ( password !== UNAUTHENTICATED ) {
You can’t perform that action at this time.
0 commit comments